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.

10603 lines
339 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. Ext.ns('Ext.ux.grid');
  8. /**
  9. * @class Ext.ux.grid.BufferView
  10. * @extends Ext.grid.GridView
  11. * A custom GridView which renders rows on an as-needed basis.
  12. */
  13. Ext.ux.grid.BufferView = Ext.extend(Ext.grid.GridView, {
  14. /**
  15. * @cfg {Number} rowHeight
  16. * The height of a row in the grid.
  17. */
  18. rowHeight: 19,
  19. /**
  20. * @cfg {Number} borderHeight
  21. * The combined height of border-top and border-bottom of a row.
  22. */
  23. borderHeight: 2,
  24. /**
  25. * @cfg {Boolean/Number} scrollDelay
  26. * The number of milliseconds before rendering rows out of the visible
  27. * viewing area. Defaults to 100. Rows will render immediately with a config
  28. * of false.
  29. */
  30. scrollDelay: 100,
  31. /**
  32. * @cfg {Number} cacheSize
  33. * The number of rows to look forward and backwards from the currently viewable
  34. * area. The cache applies only to rows that have been rendered already.
  35. */
  36. cacheSize: 20,
  37. /**
  38. * @cfg {Number} cleanDelay
  39. * The number of milliseconds to buffer cleaning of extra rows not in the
  40. * cache.
  41. */
  42. cleanDelay: 500,
  43. initTemplates : function(){
  44. Ext.ux.grid.BufferView.superclass.initTemplates.call(this);
  45. var ts = this.templates;
  46. // empty div to act as a place holder for a row
  47. ts.rowHolder = new Ext.Template(
  48. '<div class="x-grid3-row {alt}" style="{tstyle}"></div>'
  49. );
  50. ts.rowHolder.disableFormats = true;
  51. ts.rowHolder.compile();
  52. ts.rowBody = new Ext.Template(
  53. '<table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
  54. '<tbody><tr>{cells}</tr>',
  55. (this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
  56. '</tbody></table>'
  57. );
  58. ts.rowBody.disableFormats = true;
  59. ts.rowBody.compile();
  60. },
  61. getStyleRowHeight : function(){
  62. return Ext.isBorderBox ? (this.rowHeight + this.borderHeight) : this.rowHeight;
  63. },
  64. getCalculatedRowHeight : function(){
  65. return this.rowHeight + this.borderHeight;
  66. },
  67. getVisibleRowCount : function(){
  68. var rh = this.getCalculatedRowHeight(),
  69. visibleHeight = this.scroller.dom.clientHeight;
  70. return (visibleHeight < 1) ? 0 : Math.ceil(visibleHeight / rh);
  71. },
  72. getVisibleRows: function(){
  73. var count = this.getVisibleRowCount(),
  74. sc = this.scroller.dom.scrollTop,
  75. start = (sc === 0 ? 0 : Math.floor(sc/this.getCalculatedRowHeight())-1);
  76. return {
  77. first: Math.max(start, 0),
  78. last: Math.min(start + count + 2, this.ds.getCount()-1)
  79. };
  80. },
  81. doRender : function(cs, rs, ds, startRow, colCount, stripe, onlyBody){
  82. var ts = this.templates,
  83. ct = ts.cell,
  84. rt = ts.row,
  85. rb = ts.rowBody,
  86. last = colCount-1,
  87. rh = this.getStyleRowHeight(),
  88. vr = this.getVisibleRows(),
  89. tstyle = 'width:'+this.getTotalWidth()+';height:'+rh+'px;',
  90. // buffers
  91. buf = [],
  92. cb,
  93. c,
  94. p = {},
  95. rp = {tstyle: tstyle},
  96. r;
  97. for (var j = 0, len = rs.length; j < len; j++) {
  98. r = rs[j]; cb = [];
  99. var rowIndex = (j+startRow),
  100. visible = rowIndex >= vr.first && rowIndex <= vr.last;
  101. if (visible) {
  102. for (var i = 0; i < colCount; i++) {
  103. c = cs[i];
  104. p.id = c.id;
  105. p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
  106. p.attr = p.cellAttr = "";
  107. p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
  108. p.style = c.style;
  109. if (p.value === undefined || p.value === "") {
  110. p.value = "&#160;";
  111. }
  112. if (r.dirty && typeof r.modified[c.name] !== 'undefined') {
  113. p.css += ' x-grid3-dirty-cell';
  114. }
  115. cb[cb.length] = ct.apply(p);
  116. }
  117. }
  118. var alt = [];
  119. if(stripe && ((rowIndex+1) % 2 === 0)){
  120. alt[0] = "x-grid3-row-alt";
  121. }
  122. if(r.dirty){
  123. alt[1] = " x-grid3-dirty-row";
  124. }
  125. rp.cols = colCount;
  126. if(this.getRowClass){
  127. alt[2] = this.getRowClass(r, rowIndex, rp, ds);
  128. }
  129. rp.alt = alt.join(" ");
  130. rp.cells = cb.join("");
  131. buf[buf.length] = !visible ? ts.rowHolder.apply(rp) : (onlyBody ? rb.apply(rp) : rt.apply(rp));
  132. }
  133. return buf.join("");
  134. },
  135. isRowRendered: function(index){
  136. var row = this.getRow(index);
  137. return row && row.childNodes.length > 0;
  138. },
  139. syncScroll: function(){
  140. Ext.ux.grid.BufferView.superclass.syncScroll.apply(this, arguments);
  141. this.update();
  142. },
  143. // a (optionally) buffered method to update contents of gridview
  144. update: function(){
  145. if (this.scrollDelay) {
  146. if (!this.renderTask) {
  147. this.renderTask = new Ext.util.DelayedTask(this.doUpdate, this);
  148. }
  149. this.renderTask.delay(this.scrollDelay);
  150. }else{
  151. this.doUpdate();
  152. }
  153. },
  154. onRemove : function(ds, record, index, isUpdate){
  155. Ext.ux.grid.BufferView.superclass.onRemove.apply(this, arguments);
  156. if(isUpdate !== true){
  157. this.update();
  158. }
  159. },
  160. doUpdate: function(){
  161. if (this.getVisibleRowCount() > 0) {
  162. var g = this.grid,
  163. cm = g.colModel,
  164. ds = g.store,
  165. cs = this.getColumnData(),
  166. vr = this.getVisibleRows(),
  167. row;
  168. for (var i = vr.first; i <= vr.last; i++) {
  169. // if row is NOT rendered and is visible, render it
  170. if(!this.isRowRendered(i) && (row = this.getRow(i))){
  171. var html = this.doRender(cs, [ds.getAt(i)], ds, i, cm.getColumnCount(), g.stripeRows, true);
  172. row.innerHTML = html;
  173. }
  174. }
  175. this.clean();
  176. }
  177. },
  178. // a buffered method to clean rows
  179. clean : function(){
  180. if(!this.cleanTask){
  181. this.cleanTask = new Ext.util.DelayedTask(this.doClean, this);
  182. }
  183. this.cleanTask.delay(this.cleanDelay);
  184. },
  185. doClean: function(){
  186. if (this.getVisibleRowCount() > 0) {
  187. var vr = this.getVisibleRows();
  188. vr.first -= this.cacheSize;
  189. vr.last += this.cacheSize;
  190. var i = 0, rows = this.getRows();
  191. // if first is less than 0, all rows have been rendered
  192. // so lets clean the end...
  193. if(vr.first <= 0){
  194. i = vr.last + 1;
  195. }
  196. for(var len = this.ds.getCount(); i < len; i++){
  197. // if current row is outside of first and last and
  198. // has content, update the innerHTML to nothing
  199. if ((i < vr.first || i > vr.last) && rows[i].innerHTML) {
  200. rows[i].innerHTML = '';
  201. }
  202. }
  203. }
  204. },
  205. removeTask: function(name){
  206. var task = this[name];
  207. if(task && task.cancel){
  208. task.cancel();
  209. this[name] = null;
  210. }
  211. },
  212. destroy : function(){
  213. this.removeTask('cleanTask');
  214. this.removeTask('renderTask');
  215. Ext.ux.grid.BufferView.superclass.destroy.call(this);
  216. },
  217. layout: function(){
  218. Ext.ux.grid.BufferView.superclass.layout.call(this);
  219. this.update();
  220. }
  221. });// We are adding these custom layouts to a namespace that does not
  222. // exist by default in Ext, so we have to add the namespace first:
  223. Ext.ns('Ext.ux.layout');
  224. /**
  225. * @class Ext.ux.layout.CenterLayout
  226. * @extends Ext.layout.FitLayout
  227. * <p>This is a very simple layout style used to center contents within a container. This layout works within
  228. * nested containers and can also be used as expected as a Viewport layout to center the page layout.</p>
  229. * <p>As a subclass of FitLayout, CenterLayout expects to have a single child panel of the container that uses
  230. * the layout. The layout does not require any config options, although the child panel contained within the
  231. * layout must provide a fixed or percentage width. The child panel's height will fit to the container by
  232. * default, but you can specify <tt>autoHeight:true</tt> to allow it to autosize based on its content height.
  233. * Example usage:</p>
  234. * <pre><code>
  235. // The content panel is centered in the container
  236. var p = new Ext.Panel({
  237. title: 'Center Layout',
  238. layout: 'ux.center',
  239. items: [{
  240. title: 'Centered Content',
  241. width: '75%',
  242. html: 'Some content'
  243. }]
  244. });
  245. // If you leave the title blank and specify no border
  246. // you'll create a non-visual, structural panel just
  247. // for centering the contents in the main container.
  248. var p = new Ext.Panel({
  249. layout: 'ux.center',
  250. border: false,
  251. items: [{
  252. title: 'Centered Content',
  253. width: 300,
  254. autoHeight: true,
  255. html: 'Some content'
  256. }]
  257. });
  258. </code></pre>
  259. */
  260. Ext.ux.layout.CenterLayout = Ext.extend(Ext.layout.FitLayout, {
  261. // private
  262. setItemSize : function(item, size){
  263. this.container.addClass('ux-layout-center');
  264. item.addClass('ux-layout-center-item');
  265. if(item && size.height > 0){
  266. if(item.width){
  267. size.width = item.width;
  268. }
  269. item.setSize(size);
  270. }
  271. }
  272. });
  273. Ext.Container.LAYOUTS['ux.center'] = Ext.ux.layout.CenterLayout;
  274. Ext.ns('Ext.ux.grid');
  275. /**
  276. * @class Ext.ux.grid.CheckColumn
  277. * @extends Ext.grid.Column
  278. * <p>A Column subclass which renders a checkbox in each column cell which toggles the truthiness of the associated data field on click.</p>
  279. * <p><b>Note. As of ExtJS 3.3 this no longer has to be configured as a plugin of the GridPanel.</b></p>
  280. * <p>Example usage:</p>
  281. * <pre><code>
  282. var cm = new Ext.grid.ColumnModel([{
  283. header: 'Foo',
  284. ...
  285. },{
  286. xtype: 'checkcolumn',
  287. header: 'Indoor?',
  288. dataIndex: 'indoor',
  289. width: 55
  290. }
  291. ]);
  292. // create the grid
  293. var grid = new Ext.grid.EditorGridPanel({
  294. ...
  295. colModel: cm,
  296. ...
  297. });
  298. * </code></pre>
  299. * In addition to toggling a Boolean value within the record data, this
  300. * class toggles a css class between <tt>'x-grid3-check-col'</tt> and
  301. * <tt>'x-grid3-check-col-on'</tt> to alter the background image used for
  302. * a column.
  303. */
  304. Ext.ux.grid.CheckColumn = Ext.extend(Ext.grid.Column, {
  305. /**
  306. * @private
  307. * Process and refire events routed from the GridView's processEvent method.
  308. */
  309. processEvent : function(name, e, grid, rowIndex, colIndex){
  310. if (name == 'mousedown') {
  311. var record = grid.store.getAt(rowIndex);
  312. record.set(this.dataIndex, !record.data[this.dataIndex]);
  313. return false; // Cancel row selection.
  314. } else {
  315. return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments);
  316. }
  317. },
  318. renderer : function(v, p, record){
  319. p.css += ' x-grid3-check-col-td';
  320. return String.format('<div class="x-grid3-check-col{0}">&#160;</div>', v ? '-on' : '');
  321. },
  322. // Deprecate use as a plugin. Remove in 4.0
  323. init: Ext.emptyFn
  324. });
  325. // register ptype. Deprecate. Remove in 4.0
  326. Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn);
  327. // backwards compat. Remove in 4.0
  328. Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn;
  329. // register Column xtype
  330. Ext.grid.Column.types.checkcolumn = Ext.ux.grid.CheckColumn;Ext.ns('Ext.ux.grid');
  331. Ext.ux.grid.ColumnHeaderGroup = Ext.extend(Ext.util.Observable, {
  332. constructor: function(config){
  333. this.config = config;
  334. },
  335. init: function(grid){
  336. Ext.applyIf(grid.colModel, this.config);
  337. Ext.apply(grid.getView(), this.viewConfig);
  338. },
  339. viewConfig: {
  340. initTemplates: function(){
  341. this.constructor.prototype.initTemplates.apply(this, arguments);
  342. var ts = this.templates || {};
  343. if(!ts.gcell){
  344. ts.gcell = new Ext.XTemplate('<td class="x-grid3-hd x-grid3-gcell x-grid3-td-{id} ux-grid-hd-group-row-{row} {cls}" style="{style}">', '<div {tooltip} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '', '{value}</div></td>');
  345. }
  346. this.templates = ts;
  347. this.hrowRe = new RegExp("ux-grid-hd-group-row-(\\d+)", "");
  348. },
  349. renderHeaders: function(){
  350. var ts = this.templates, headers = [], cm = this.cm, rows = cm.rows, tstyle = 'width:' + this.getTotalWidth() + ';';
  351. for(var row = 0, rlen = rows.length; row < rlen; row++){
  352. var r = rows[row], cells = [];
  353. for(var i = 0, gcol = 0, len = r.length; i < len; i++){
  354. var group = r[i];
  355. group.colspan = group.colspan || 1;
  356. var id = this.getColumnId(group.dataIndex ? cm.findColumnIndex(group.dataIndex) : gcol), gs = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupStyle.call(this, group, gcol);
  357. cells[i] = ts.gcell.apply({
  358. cls: 'ux-grid-hd-group-cell',
  359. id: id,
  360. row: row,
  361. style: 'width:' + gs.width + ';' + (gs.hidden ? 'display:none;' : '') + (group.align ? 'text-align:' + group.align + ';' : ''),
  362. tooltip: group.tooltip ? (Ext.QuickTips.isEnabled() ? 'ext:qtip' : 'title') + '="' + group.tooltip + '"' : '',
  363. istyle: group.align == 'right' ? 'padding-right:16px' : '',
  364. btn: this.grid.enableHdMenu && group.header,
  365. value: group.header || '&nbsp;'
  366. });
  367. gcol += group.colspan;
  368. }
  369. headers[row] = ts.header.apply({
  370. tstyle: tstyle,
  371. cells: cells.join('')
  372. });
  373. }
  374. headers.push(this.constructor.prototype.renderHeaders.apply(this, arguments));
  375. return headers.join('');
  376. },
  377. onColumnWidthUpdated: function(){
  378. this.constructor.prototype.onColumnWidthUpdated.apply(this, arguments);
  379. Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
  380. },
  381. onAllColumnWidthsUpdated: function(){
  382. this.constructor.prototype.onAllColumnWidthsUpdated.apply(this, arguments);
  383. Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
  384. },
  385. onColumnHiddenUpdated: function(){
  386. this.constructor.prototype.onColumnHiddenUpdated.apply(this, arguments);
  387. Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
  388. },
  389. getHeaderCell: function(index){
  390. return this.mainHd.query(this.cellSelector)[index];
  391. },
  392. findHeaderCell: function(el){
  393. return el ? this.fly(el).findParent('td.x-grid3-hd', this.cellSelectorDepth) : false;
  394. },
  395. findHeaderIndex: function(el){
  396. var cell = this.findHeaderCell(el);
  397. return cell ? this.getCellIndex(cell) : false;
  398. },
  399. updateSortIcon: function(col, dir){
  400. var sc = this.sortClasses, hds = this.mainHd.select(this.cellSelector).removeClass(sc);
  401. hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
  402. },
  403. handleHdDown: function(e, t){
  404. var el = Ext.get(t);
  405. if(el.hasClass('x-grid3-hd-btn')){
  406. e.stopEvent();
  407. var hd = this.findHeaderCell(t);
  408. Ext.fly(hd).addClass('x-grid3-hd-menu-open');
  409. var index = this.getCellIndex(hd);
  410. this.hdCtxIndex = index;
  411. var ms = this.hmenu.items, cm = this.cm;
  412. ms.get('asc').setDisabled(!cm.isSortable(index));
  413. ms.get('desc').setDisabled(!cm.isSortable(index));
  414. this.hmenu.on('hide', function(){
  415. Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
  416. }, this, {
  417. single: true
  418. });
  419. this.hmenu.show(t, 'tl-bl?');
  420. }else if(el.hasClass('ux-grid-hd-group-cell') || Ext.fly(t).up('.ux-grid-hd-group-cell')){
  421. e.stopEvent();
  422. }
  423. },
  424. handleHdMove: function(e, t){
  425. var hd = this.findHeaderCell(this.activeHdRef);
  426. if(hd && !this.headersDisabled && !Ext.fly(hd).hasClass('ux-grid-hd-group-cell')){
  427. var hw = this.splitHandleWidth || 5, r = this.activeHdRegion, x = e.getPageX(), ss = hd.style, cur = '';
  428. if(this.grid.enableColumnResize !== false){
  429. if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex - 1)){
  430. cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize
  431. // not
  432. // always
  433. // supported
  434. }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
  435. cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
  436. }
  437. }
  438. ss.cursor = cur;
  439. }
  440. },
  441. handleHdOver: function(e, t){
  442. var hd = this.findHeaderCell(t);
  443. if(hd && !this.headersDisabled){
  444. this.activeHdRef = t;
  445. this.activeHdIndex = this.getCellIndex(hd);
  446. var fly = this.fly(hd);
  447. this.activeHdRegion = fly.getRegion();
  448. if(!(this.cm.isMenuDisabled(this.activeHdIndex) || fly.hasClass('ux-grid-hd-group-cell'))){
  449. fly.addClass('x-grid3-hd-over');
  450. this.activeHdBtn = fly.child('.x-grid3-hd-btn');
  451. if(this.activeHdBtn){
  452. this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight - 1) + 'px';
  453. }
  454. }
  455. }
  456. },
  457. handleHdOut: function(e, t){
  458. var hd = this.findHeaderCell(t);
  459. if(hd && (!Ext.isIE || !e.within(hd, true))){
  460. this.activeHdRef = null;
  461. this.fly(hd).removeClass('x-grid3-hd-over');
  462. hd.style.cursor = '';
  463. }
  464. },
  465. handleHdMenuClick: function(item){
  466. var index = this.hdCtxIndex, cm = this.cm, ds = this.ds, id = item.getItemId();
  467. switch(id){
  468. case 'asc':
  469. ds.sort(cm.getDataIndex(index), 'ASC');
  470. break;
  471. case 'desc':
  472. ds.sort(cm.getDataIndex(index), 'DESC');
  473. break;
  474. default:
  475. if(id.substr(0, 6) == 'group-'){
  476. var i = id.split('-'), row = parseInt(i[1], 10), col = parseInt(i[2], 10), r = this.cm.rows[row], group, gcol = 0;
  477. for(var i = 0, len = r.length; i < len; i++){
  478. group = r[i];
  479. if(col >= gcol && col < gcol + group.colspan){
  480. break;
  481. }
  482. gcol += group.colspan;
  483. }
  484. if(item.checked){
  485. var max = cm.getColumnsBy(this.isHideableColumn, this).length;
  486. for(var i = gcol, len = gcol + group.colspan; i < len; i++){
  487. if(!cm.isHidden(i)){
  488. max--;
  489. }
  490. }
  491. if(max < 1){
  492. this.onDenyColumnHide();
  493. return false;
  494. }
  495. }
  496. for(var i = gcol, len = gcol + group.colspan; i < len; i++){
  497. if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
  498. cm.setHidden(i, item.checked);
  499. }
  500. }
  501. }else if(id.substr(0, 4) == 'col-'){
  502. index = cm.getIndexById(id.substr(4));
  503. if(index != -1){
  504. if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
  505. this.onDenyColumnHide();
  506. return false;
  507. }
  508. cm.setHidden(index, item.checked);
  509. }
  510. }
  511. if(id.substr(0, 6) == 'group-' || id.substr(0, 4) == 'col-'){
  512. item.checked = !item.checked;
  513. if(item.menu){
  514. var updateChildren = function(menu){
  515. menu.items.each(function(childItem){
  516. if(!childItem.disabled){
  517. childItem.setChecked(item.checked, false);
  518. if(childItem.menu){
  519. updateChildren(childItem.menu);
  520. }
  521. }
  522. });
  523. }
  524. updateChildren(item.menu);
  525. }
  526. var parentMenu = item, parentItem;
  527. while(parentMenu = parentMenu.parentMenu){
  528. if(!parentMenu.parentMenu || !(parentItem = parentMenu.parentMenu.items.get(parentMenu.getItemId())) || !parentItem.setChecked){
  529. break;
  530. }
  531. var checked = parentMenu.items.findIndexBy(function(m){
  532. return m.checked;
  533. }) >= 0;
  534. parentItem.setChecked(checked, true);
  535. }
  536. item.checked = !item.checked;
  537. }
  538. }
  539. return true;
  540. },
  541. beforeColMenuShow: function(){
  542. var cm = this.cm, rows = this.cm.rows;
  543. this.colMenu.removeAll();
  544. for(var col = 0, clen = cm.getColumnCount(); col < clen; col++){
  545. var menu = this.colMenu, title = cm.getColumnHeader(col), text = [];
  546. if(cm.config[col].fixed !== true && cm.config[col].hideable !== false){
  547. for(var row = 0, rlen = rows.length; row < rlen; row++){
  548. var r = rows[row], group, gcol = 0;
  549. for(var i = 0, len = r.length; i < len; i++){
  550. group = r[i];
  551. if(col >= gcol && col < gcol + group.colspan){
  552. break;
  553. }
  554. gcol += group.colspan;
  555. }
  556. if(group && group.header){
  557. if(cm.hierarchicalColMenu){
  558. var gid = 'group-' + row + '-' + gcol,
  559. item = menu.items ? menu.getComponent(gid) : null,
  560. submenu = item ? item.menu : null;
  561. if(!submenu){
  562. submenu = new Ext.menu.Menu({
  563. itemId: gid
  564. });
  565. submenu.on("itemclick", this.handleHdMenuClick, this);
  566. var checked = false, disabled = true;
  567. for(var c = gcol, lc = gcol + group.colspan; c < lc; c++){
  568. if(!cm.isHidden(c)){
  569. checked = true;
  570. }
  571. if(cm.config[c].hideable !== false){
  572. disabled = false;
  573. }
  574. }
  575. menu.add({
  576. itemId: gid,
  577. text: group.header,
  578. menu: submenu,
  579. hideOnClick: false,
  580. checked: checked,
  581. disabled: disabled
  582. });
  583. }
  584. menu = submenu;
  585. }else{
  586. text.push(group.header);
  587. }
  588. }
  589. }
  590. text.push(title);
  591. menu.add(new Ext.menu.CheckItem({
  592. itemId: "col-" + cm.getColumnId(col),
  593. text: text.join(' '),
  594. checked: !cm.isHidden(col),
  595. hideOnClick: false,
  596. disabled: cm.config[col].hideable === false
  597. }));
  598. }
  599. }
  600. },
  601. afterRenderUI: function(){
  602. this.constructor.prototype.afterRenderUI.apply(this, arguments);
  603. Ext.apply(this.columnDrop, Ext.ux.grid.ColumnHeaderGroup.prototype.columnDropConfig);
  604. Ext.apply(this.splitZone, Ext.ux.grid.ColumnHeaderGroup.prototype.splitZoneConfig);
  605. }
  606. },
  607. splitZoneConfig: {
  608. allowHeaderDrag: function(e){
  609. return !e.getTarget(null, null, true).hasClass('ux-grid-hd-group-cell');
  610. }
  611. },
  612. columnDropConfig: {
  613. getTargetFromEvent: function(e){
  614. var t = Ext.lib.Event.getTarget(e);
  615. return this.view.findHeaderCell(t);
  616. },
  617. positionIndicator: function(h, n, e){
  618. var data = Ext.ux.grid.ColumnHeaderGroup.prototype.getDragDropData.call(this, h, n, e);
  619. if(data === false){
  620. return false;
  621. }
  622. var px = data.px + this.proxyOffsets[0];
  623. this.proxyTop.setLeftTop(px, data.r.top + this.proxyOffsets[1]);
  624. this.proxyTop.show();
  625. this.proxyBottom.setLeftTop(px, data.r.bottom);
  626. this.proxyBottom.show();
  627. return data.pt;
  628. },
  629. onNodeDrop: function(n, dd, e, data){
  630. var h = data.header;
  631. if(h != n){
  632. var d = Ext.ux.grid.ColumnHeaderGroup.prototype.getDragDropData.call(this, h, n, e);
  633. if(d === false){
  634. return false;
  635. }
  636. var cm = this.grid.colModel, right = d.oldIndex < d.newIndex, rows = cm.rows;
  637. for(var row = d.row, rlen = rows.length; row < rlen; row++){
  638. var r = rows[row], len = r.length, fromIx = 0, span = 1, toIx = len;
  639. for(var i = 0, gcol = 0; i < len; i++){
  640. var group = r[i];
  641. if(d.oldIndex >= gcol && d.oldIndex < gcol + group.colspan){
  642. fromIx = i;
  643. }
  644. if(d.oldIndex + d.colspan - 1 >= gcol && d.oldIndex + d.colspan - 1 < gcol + group.colspan){
  645. span = i - fromIx + 1;
  646. }
  647. if(d.newIndex >= gcol && d.newIndex < gcol + group.colspan){
  648. toIx = i;
  649. }
  650. gcol += group.colspan;
  651. }
  652. var groups = r.splice(fromIx, span);
  653. rows[row] = r.splice(0, toIx - (right ? span : 0)).concat(groups).concat(r);
  654. }
  655. for(var c = 0; c < d.colspan; c++){
  656. var oldIx = d.oldIndex + (right ? 0 : c), newIx = d.newIndex + (right ? -1 : c);
  657. cm.moveColumn(oldIx, newIx);
  658. this.grid.fireEvent("columnmove", oldIx, newIx);
  659. }
  660. return true;
  661. }
  662. return false;
  663. }
  664. },
  665. getGroupStyle: function(group, gcol){
  666. var width = 0, hidden = true;
  667. for(var i = gcol, len = gcol + group.colspan; i < len; i++){
  668. if(!this.cm.isHidden(i)){
  669. var cw = this.cm.getColumnWidth(i);
  670. if(typeof cw == 'number'){
  671. width += cw;
  672. }
  673. hidden = false;
  674. }
  675. }
  676. return {
  677. width: (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? width : Math.max(width - this.borderWidth, 0)) + 'px',
  678. hidden: hidden
  679. };
  680. },
  681. updateGroupStyles: function(col){
  682. var tables = this.mainHd.query('.x-grid3-header-offset > table'), tw = this.getTotalWidth(), rows = this.cm.rows;
  683. for(var row = 0; row < tables.length; row++){
  684. tables[row].style.width = tw;
  685. if(row < rows.length){
  686. var cells = tables[row].firstChild.firstChild.childNodes;
  687. for(var i = 0, gcol = 0; i < cells.length; i++){
  688. var group = rows[row][i];
  689. if((typeof col != 'number') || (col >= gcol && col < gcol + group.colspan)){
  690. var gs = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupStyle.call(this, group, gcol);
  691. cells[i].style.width = gs.width;
  692. cells[i].style.display = gs.hidden ? 'none' : '';
  693. }
  694. gcol += group.colspan;
  695. }
  696. }
  697. }
  698. },
  699. getGroupRowIndex: function(el){
  700. if(el){
  701. var m = el.className.match(this.hrowRe);
  702. if(m && m[1]){
  703. return parseInt(m[1], 10);
  704. }
  705. }
  706. return this.cm.rows.length;
  707. },
  708. getGroupSpan: function(row, col){
  709. if(row < 0){
  710. return {
  711. col: 0,
  712. colspan: this.cm.getColumnCount()
  713. };
  714. }
  715. var r = this.cm.rows[row];
  716. if(r){
  717. for(var i = 0, gcol = 0, len = r.length; i < len; i++){
  718. var group = r[i];
  719. if(col >= gcol && col < gcol + group.colspan){
  720. return {
  721. col: gcol,
  722. colspan: group.colspan
  723. };
  724. }
  725. gcol += group.colspan;
  726. }
  727. return {
  728. col: gcol,
  729. colspan: 0
  730. };
  731. }
  732. return {
  733. col: col,
  734. colspan: 1
  735. };
  736. },
  737. getDragDropData: function(h, n, e){
  738. if(h.parentNode != n.parentNode){
  739. return false;
  740. }
  741. var cm = this.grid.colModel, x = Ext.lib.Event.getPageX(e), r = Ext.lib.Dom.getRegion(n.firstChild), px, pt;
  742. if((r.right - x) <= (r.right - r.left) / 2){
  743. px = r.right + this.view.borderWidth;
  744. pt = "after";
  745. }else{
  746. px = r.left;
  747. pt = "before";
  748. }
  749. var oldIndex = this.view.getCellIndex(h), newIndex = this.view.getCellIndex(n);
  750. if(cm.isFixed(newIndex)){
  751. return false;
  752. }
  753. var row = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupRowIndex.call(this.view, h),
  754. oldGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row, oldIndex),
  755. newGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row, newIndex),
  756. oldIndex = oldGroup.col;
  757. newIndex = newGroup.col + (pt == "after" ? newGroup.colspan : 0);
  758. if(newIndex >= oldGroup.col && newIndex <= oldGroup.col + oldGroup.colspan){
  759. return false;
  760. }
  761. var parentGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row - 1, oldIndex);
  762. if(newIndex < parentGroup.col || newIndex > parentGroup.col + parentGroup.colspan){
  763. return false;
  764. }
  765. return {
  766. r: r,
  767. px: px,
  768. pt: pt,
  769. row: row,
  770. oldIndex: oldIndex,
  771. newIndex: newIndex,
  772. colspan: oldGroup.colspan
  773. };
  774. }
  775. });Ext.ns('Ext.ux.tree');
  776. /**
  777. * @class Ext.ux.tree.ColumnTree
  778. * @extends Ext.tree.TreePanel
  779. *
  780. * @xtype columntree
  781. */
  782. Ext.ux.tree.ColumnTree = Ext.extend(Ext.tree.TreePanel, {
  783. lines : false,
  784. borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
  785. cls : 'x-column-tree',
  786. onRender : function(){
  787. Ext.tree.ColumnTree.superclass.onRender.apply(this, arguments);
  788. this.headers = this.header.createChild({cls:'x-tree-headers'});
  789. var cols = this.columns, c;
  790. var totalWidth = 0;
  791. var scrollOffset = 19; // similar to Ext.grid.GridView default
  792. for(var i = 0, len = cols.length; i < len; i++){
  793. c = cols[i];
  794. totalWidth += c.width;
  795. this.headers.createChild({
  796. cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
  797. cn: {
  798. cls:'x-tree-hd-text',
  799. html: c.header
  800. },
  801. style:'width:'+(c.width-this.borderWidth)+'px;'
  802. });
  803. }
  804. this.headers.createChild({cls:'x-clear'});
  805. // prevent floats from wrapping when clipped
  806. this.headers.setWidth(totalWidth+scrollOffset);
  807. this.innerCt.setWidth(totalWidth);
  808. }
  809. });
  810. Ext.reg('columntree', Ext.ux.tree.ColumnTree);
  811. //backwards compat
  812. Ext.tree.ColumnTree = Ext.ux.tree.ColumnTree;
  813. /**
  814. * @class Ext.ux.tree.ColumnNodeUI
  815. * @extends Ext.tree.TreeNodeUI
  816. */
  817. Ext.ux.tree.ColumnNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  818. focus: Ext.emptyFn, // prevent odd scrolling behavior
  819. renderElements : function(n, a, targetNode, bulkRender){
  820. this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
  821. var t = n.getOwnerTree();
  822. var cols = t.columns;
  823. var bw = t.borderWidth;
  824. var c = cols[0];
  825. var buf = [
  826. '<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf ', a.cls,'">',
  827. '<div class="x-tree-col" style="width:',c.width-bw,'px;">',
  828. '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
  829. '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
  830. '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on">',
  831. '<a hidefocus="on" class="x-tree-node-anchor" href="',a.href ? a.href : "#",'" tabIndex="1" ',
  832. a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '>',
  833. '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</span></a>",
  834. "</div>"];
  835. for(var i = 1, len = cols.length; i < len; i++){
  836. c = cols[i];
  837. buf.push('<div class="x-tree-col ',(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
  838. '<div class="x-tree-col-text">',(c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</div>",
  839. "</div>");
  840. }
  841. buf.push(
  842. '<div class="x-clear"></div></div>',
  843. '<ul class="x-tree-node-ct" style="display:none;"></ul>',
  844. "</li>");
  845. if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
  846. this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
  847. n.nextSibling.ui.getEl(), buf.join(""));
  848. }else{
  849. this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
  850. }
  851. this.elNode = this.wrap.childNodes[0];
  852. this.ctNode = this.wrap.childNodes[1];
  853. var cs = this.elNode.firstChild.childNodes;
  854. this.indentNode = cs[0];
  855. this.ecNode = cs[1];
  856. this.iconNode = cs[2];
  857. this.anchor = cs[3];
  858. this.textNode = cs[3].firstChild;
  859. }
  860. });
  861. //backwards compat
  862. Ext.tree.ColumnNodeUI = Ext.ux.tree.ColumnNodeUI;
  863. /**
  864. * @class Ext.DataView.LabelEditor
  865. * @extends Ext.Editor
  866. *
  867. */
  868. Ext.DataView.LabelEditor = Ext.extend(Ext.Editor, {
  869. alignment: "tl-tl",
  870. hideEl : false,
  871. cls: "x-small-editor",
  872. shim: false,
  873. completeOnEnter: true,
  874. cancelOnEsc: true,
  875. labelSelector: 'span.x-editable',
  876. constructor: function(cfg, field){
  877. Ext.DataView.LabelEditor.superclass.constructor.call(this,
  878. field || new Ext.form.TextField({
  879. allowBlank: false,
  880. growMin:90,
  881. growMax:240,
  882. grow:true,
  883. selectOnFocus:true
  884. }), cfg
  885. );
  886. },
  887. init : function(view){
  888. this.view = view;
  889. view.on('render', this.initEditor, this);
  890. this.on('complete', this.onSave, this);
  891. },
  892. initEditor : function(){
  893. this.view.on({
  894. scope: this,
  895. containerclick: this.doBlur,
  896. click: this.doBlur
  897. });
  898. this.view.getEl().on('mousedown', this.onMouseDown, this, {delegate: this.labelSelector});
  899. },
  900. doBlur: function(){
  901. if(this.editing){
  902. this.field.blur();
  903. }
  904. },
  905. onMouseDown : function(e, target){
  906. if(!e.ctrlKey && !e.shiftKey){
  907. var item = this.view.findItemFromChild(target);
  908. e.stopEvent();
  909. var record = this.view.store.getAt(this.view.indexOf(item));
  910. this.startEdit(target, record.data[this.dataIndex]);
  911. this.activeRecord = record;
  912. }else{
  913. e.preventDefault();
  914. }
  915. },
  916. onSave : function(ed, value){
  917. this.activeRecord.set(this.dataIndex, value);
  918. }
  919. });
  920. Ext.DataView.DragSelector = function(cfg){
  921. cfg = cfg || {};
  922. var view, proxy, tracker;
  923. var rs, bodyRegion, dragRegion = new Ext.lib.Region(0,0,0,0);
  924. var dragSafe = cfg.dragSafe === true;
  925. this.init = function(dataView){
  926. view = dataView;
  927. view.on('render', onRender);
  928. };
  929. function fillRegions(){
  930. rs = [];
  931. view.all.each(function(el){
  932. rs[rs.length] = el.getRegion();
  933. });
  934. bodyRegion = view.el.getRegion();
  935. }
  936. function cancelClick(){
  937. return false;
  938. }
  939. function onBeforeStart(e){
  940. return !dragSafe || e.target == view.el.dom;
  941. }
  942. function onStart(e){
  943. view.on('containerclick', cancelClick, view, {single:true});
  944. if(!proxy){
  945. proxy = view.el.createChild({cls:'x-view-selector'});
  946. }else{
  947. if(proxy.dom.parentNode !== view.el.dom){
  948. view.el.dom.appendChild(proxy.dom);
  949. }
  950. proxy.setDisplayed('block');
  951. }
  952. fillRegions();
  953. view.clearSelections();
  954. }
  955. function onDrag(e){
  956. var startXY = tracker.startXY;
  957. var xy = tracker.getXY();
  958. var x = Math.min(startXY[0], xy[0]);
  959. var y = Math.min(startXY[1], xy[1]);
  960. var w = Math.abs(startXY[0] - xy[0]);
  961. var h = Math.abs(startXY[1] - xy[1]);
  962. dragRegion.left = x;
  963. dragRegion.top = y;
  964. dragRegion.right = x+w;
  965. dragRegion.bottom = y+h;
  966. dragRegion.constrainTo(bodyRegion);
  967. proxy.setRegion(dragRegion);
  968. for(var i = 0, len = rs.length; i < len; i++){
  969. var r = rs[i], sel = dragRegion.intersect(r);
  970. if(sel && !r.selected){
  971. r.selected = true;
  972. view.select(i, true);
  973. }else if(!sel && r.selected){
  974. r.selected = false;
  975. view.deselect(i);
  976. }
  977. }
  978. }
  979. function onEnd(e){
  980. if (!Ext.isIE) {
  981. view.un('containerclick', cancelClick, view);
  982. }
  983. if(proxy){
  984. proxy.setDisplayed(false);
  985. }
  986. }
  987. function onRender(view){
  988. tracker = new Ext.dd.DragTracker({
  989. onBeforeStart: onBeforeStart,
  990. onStart: onStart,
  991. onDrag: onDrag,
  992. onEnd: onEnd
  993. });
  994. tracker.initEl(view.el);
  995. }
  996. };Ext.ns('Ext.ux.form');
  997. /**
  998. * @class Ext.ux.form.FileUploadField
  999. * @extends Ext.form.TextField
  1000. * Creates a file upload field.
  1001. * @xtype fileuploadfield
  1002. */
  1003. Ext.ux.form.FileUploadField = Ext.extend(Ext.form.TextField, {
  1004. /**
  1005. * @cfg {String} buttonText The button text to display on the upload button (defaults to
  1006. * 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
  1007. * value will be used instead if available.
  1008. */
  1009. buttonText: 'Browse...',
  1010. /**
  1011. * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
  1012. * text field (defaults to false). If true, all inherited TextField members will still be available.
  1013. */
  1014. buttonOnly: false,
  1015. /**
  1016. * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
  1017. * (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
  1018. */
  1019. buttonOffset: 3,
  1020. /**
  1021. * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
  1022. */
  1023. // private
  1024. readOnly: true,
  1025. /**
  1026. * @hide
  1027. * @method autoSize
  1028. */
  1029. autoSize: Ext.emptyFn,
  1030. // private
  1031. initComponent: function(){
  1032. Ext.ux.form.FileUploadField.superclass.initComponent.call(this);
  1033. this.addEvents(
  1034. /**
  1035. * @event fileselected
  1036. * Fires when the underlying file input field's value has changed from the user
  1037. * selecting a new file from the system file selection dialog.
  1038. * @param {Ext.ux.form.FileUploadField} this
  1039. * @param {String} value The file value returned by the underlying file input field
  1040. */
  1041. 'fileselected'
  1042. );
  1043. },
  1044. // private
  1045. onRender : function(ct, position){
  1046. Ext.ux.form.FileUploadField.superclass.onRender.call(this, ct, position);
  1047. this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
  1048. this.el.addClass('x-form-file-text');
  1049. this.el.dom.removeAttribute('name');
  1050. this.createFileInput();
  1051. var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
  1052. text: this.buttonText
  1053. });
  1054. this.button = new Ext.Button(Ext.apply(btnCfg, {
  1055. renderTo: this.wrap,
  1056. cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
  1057. }));
  1058. if(this.buttonOnly){
  1059. this.el.hide();
  1060. this.wrap.setWidth(this.button.getEl().getWidth());
  1061. }
  1062. this.bindListeners();
  1063. this.resizeEl = this.positionEl = this.wrap;
  1064. },
  1065. bindListeners: function(){
  1066. this.fileInput.on({
  1067. scope: this,
  1068. mouseenter: function() {
  1069. this.button.addClass(['x-btn-over','x-btn-focus'])
  1070. },
  1071. mouseleave: function(){
  1072. this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
  1073. },
  1074. mousedown: function(){
  1075. this.button.addClass('x-btn-click')
  1076. },
  1077. mouseup: function(){
  1078. this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
  1079. },
  1080. change: function(){
  1081. var v = this.fileInput.dom.value;
  1082. this.setValue(v);
  1083. this.fireEvent('fileselected', this, v);
  1084. }
  1085. });
  1086. },
  1087. createFileInput : function() {
  1088. this.fileInput = this.wrap.createChild({
  1089. id: this.getFileInputId(),
  1090. name: this.name||this.getId(),
  1091. cls: 'x-form-file',
  1092. tag: 'input',
  1093. type: 'file',
  1094. size: 1
  1095. });
  1096. },
  1097. reset : function(){
  1098. this.fileInput.remove();
  1099. this.createFileInput();
  1100. this.bindListeners();
  1101. Ext.ux.form.FileUploadField.superclass.reset.call(this);
  1102. },
  1103. // private
  1104. getFileInputId: function(){
  1105. return this.id + '-file';
  1106. },
  1107. // private
  1108. onResize : function(w, h){
  1109. Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);
  1110. this.wrap.setWidth(w);
  1111. if(!this.buttonOnly){
  1112. var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
  1113. this.el.setWidth(w);
  1114. }
  1115. },
  1116. // private
  1117. onDestroy: function(){
  1118. Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
  1119. Ext.destroy(this.fileInput, this.button, this.wrap);
  1120. },
  1121. onDisable: function(){
  1122. Ext.ux.form.FileUploadField.superclass.onDisable.call(this);
  1123. this.doDisable(true);
  1124. },
  1125. onEnable: function(){
  1126. Ext.ux.form.FileUploadField.superclass.onEnable.call(this);
  1127. this.doDisable(false);
  1128. },
  1129. // private
  1130. doDisable: function(disabled){
  1131. this.fileInput.dom.disabled = disabled;
  1132. this.button.setDisabled(disabled);
  1133. },
  1134. // private
  1135. preFocus : Ext.emptyFn,
  1136. // private
  1137. alignErrorIcon : function(){
  1138. this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
  1139. }
  1140. });
  1141. Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
  1142. // backwards compat
  1143. Ext.form.FileUploadField = Ext.ux.form.FileUploadField;
  1144. /**
  1145. * @class Ext.ux.GMapPanel
  1146. * @extends Ext.Panel
  1147. * @author Shea Frederick
  1148. */
  1149. Ext.ux.GMapPanel = Ext.extend(Ext.Panel, {
  1150. initComponent : function(){
  1151. var defConfig = {
  1152. plain: true,
  1153. zoomLevel: 3,
  1154. yaw: 180,
  1155. pitch: 0,
  1156. zoom: 0,
  1157. gmapType: 'map',
  1158. border: false
  1159. };
  1160. Ext.applyIf(this,defConfig);
  1161. Ext.ux.GMapPanel.superclass.initComponent.call(this);
  1162. },
  1163. afterRender : function(){
  1164. var wh = this.ownerCt.getSize();
  1165. Ext.applyIf(this, wh);
  1166. Ext.ux.GMapPanel.superclass.afterRender.call(this);
  1167. if (this.gmapType === 'map'){
  1168. this.gmap = new GMap2(this.body.dom);
  1169. }
  1170. if (this.gmapType === 'panorama'){
  1171. this.gmap = new GStreetviewPanorama(this.body.dom);
  1172. }
  1173. if (typeof this.addControl == 'object' && this.gmapType === 'map') {
  1174. this.gmap.addControl(this.addControl);
  1175. }
  1176. if (typeof this.setCenter === 'object') {
  1177. if (typeof this.setCenter.geoCodeAddr === 'string'){
  1178. this.geoCodeLookup(this.setCenter.geoCodeAddr);
  1179. }else{
  1180. if (this.gmapType === 'map'){
  1181. var point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
  1182. this.gmap.setCenter(point, this.zoomLevel);
  1183. }
  1184. if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
  1185. this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
  1186. }
  1187. }
  1188. if (this.gmapType === 'panorama'){
  1189. this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
  1190. }
  1191. }
  1192. GEvent.bind(this.gmap, 'load', this, function(){
  1193. this.onMapReady();
  1194. });
  1195. },
  1196. onMapReady : function(){
  1197. this.addMarkers(this.markers);
  1198. this.addMapControls();
  1199. this.addOptions();
  1200. },
  1201. onResize : function(w, h){
  1202. if (typeof this.getMap() == 'object') {
  1203. this.gmap.checkResize();
  1204. }
  1205. Ext.ux.GMapPanel.superclass.onResize.call(this, w, h);
  1206. },
  1207. setSize : function(width, height, animate){
  1208. if (typeof this.getMap() == 'object') {
  1209. this.gmap.checkResize();
  1210. }
  1211. Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
  1212. },
  1213. getMap : function(){
  1214. return this.gmap;
  1215. },
  1216. getCenter : function(){
  1217. return this.getMap().getCenter();
  1218. },
  1219. getCenterLatLng : function(){
  1220. var ll = this.getCenter();
  1221. return {lat: ll.lat(), lng: ll.lng()};
  1222. },
  1223. addMarkers : function(markers) {
  1224. if (Ext.isArray(markers)){
  1225. for (var i = 0; i < markers.length; i++) {
  1226. var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
  1227. this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
  1228. }
  1229. }
  1230. },
  1231. addMarker : function(point, marker, clear, center, listeners){
  1232. Ext.applyIf(marker,G_DEFAULT_ICON);
  1233. if (clear === true){
  1234. this.getMap().clearOverlays();
  1235. }
  1236. if (center === true) {
  1237. this.getMap().setCenter(point, this.zoomLevel);
  1238. }
  1239. var mark = new GMarker(point,marker);
  1240. if (typeof listeners === 'object'){
  1241. for (evt in listeners) {
  1242. GEvent.bind(mark, evt, this, listeners[evt]);
  1243. }
  1244. }
  1245. this.getMap().addOverlay(mark);
  1246. },
  1247. addMapControls : function(){
  1248. if (this.gmapType === 'map') {
  1249. if (Ext.isArray(this.mapControls)) {
  1250. for(i=0;i<this.mapControls.length;i++){
  1251. this.addMapControl(this.mapControls[i]);
  1252. }
  1253. }else if(typeof this.mapControls === 'string'){
  1254. this.addMapControl(this.mapControls);
  1255. }else if(typeof this.mapControls === 'object'){
  1256. this.getMap().addControl(this.mapControls);
  1257. }
  1258. }
  1259. },
  1260. addMapControl : function(mc){
  1261. var mcf = window[mc];
  1262. if (typeof mcf === 'function') {
  1263. this.getMap().addControl(new mcf());
  1264. }
  1265. },
  1266. addOptions : function(){
  1267. if (Ext.isArray(this.mapConfOpts)) {
  1268. var mc;
  1269. for(i=0;i<this.mapConfOpts.length;i++){
  1270. this.addOption(this.mapConfOpts[i]);
  1271. }
  1272. }else if(typeof this.mapConfOpts === 'string'){
  1273. this.addOption(this.mapConfOpts);
  1274. }
  1275. },
  1276. addOption : function(mc){
  1277. var mcf = this.getMap()[mc];
  1278. if (typeof mcf === 'function') {
  1279. this.getMap()[mc]();
  1280. }
  1281. },
  1282. geoCodeLookup : function(addr) {
  1283. this.geocoder = new GClientGeocoder();
  1284. this.geocoder.getLocations(addr, this.addAddressToMap.createDelegate(this));
  1285. },
  1286. addAddressToMap : function(response) {
  1287. if (!response || response.Status.code != 200) {
  1288. Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
  1289. }else{
  1290. place = response.Placemark[0];
  1291. addressinfo = place.AddressDetails;
  1292. accuracy = addressinfo.Accuracy;
  1293. if (accuracy === 0) {
  1294. Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
  1295. }else{
  1296. if (accuracy < 7) {
  1297. Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.<br><br>Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
  1298. }else{
  1299. point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
  1300. if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
  1301. this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);
  1302. }
  1303. }
  1304. }
  1305. }
  1306. }
  1307. });
  1308. Ext.reg('gmappanel', Ext.ux.GMapPanel); Ext.namespace('Ext.ux.grid');
  1309. /**
  1310. * @class Ext.ux.grid.GridFilters
  1311. * @extends Ext.util.Observable
  1312. * <p>GridFilter is a plugin (<code>ptype='gridfilters'</code>) for grids that
  1313. * allow for a slightly more robust representation of filtering than what is
  1314. * provided by the default store.</p>
  1315. * <p>Filtering is adjusted by the user using the grid's column header menu
  1316. * (this menu can be disabled through configuration). Through this menu users
  1317. * can configure, enable, and disable filters for each column.</p>
  1318. * <p><b><u>Features:</u></b></p>
  1319. * <div class="mdetail-params"><ul>
  1320. * <li><b>Filtering implementations</b> :
  1321. * <div class="sub-desc">
  1322. * Default filtering for Strings, Numeric Ranges, Date Ranges, Lists (which can
  1323. * be backed by a Ext.data.Store), and Boolean. Additional custom filter types
  1324. * and menus are easily created by extending Ext.ux.grid.filter.Filter.
  1325. * </div></li>
  1326. * <li><b>Graphical indicators</b> :
  1327. * <div class="sub-desc">
  1328. * Columns that are filtered have {@link #filterCls a configurable css class}
  1329. * applied to the column headers.
  1330. * </div></li>
  1331. * <li><b>Paging</b> :
  1332. * <div class="sub-desc">
  1333. * If specified as a plugin to the grid's configured PagingToolbar, the current page
  1334. * will be reset to page 1 whenever you update the filters.
  1335. * </div></li>
  1336. * <li><b>Automatic Reconfiguration</b> :
  1337. * <div class="sub-desc">
  1338. * Filters automatically reconfigure when the grid 'reconfigure' event fires.
  1339. * </div></li>
  1340. * <li><b>Stateful</b> :
  1341. * Filter information will be persisted across page loads by specifying a
  1342. * <code>stateId</code> in the Grid configuration.
  1343. * <div class="sub-desc">
  1344. * The filter collection binds to the
  1345. * <code>{@link Ext.grid.GridPanel#beforestaterestore beforestaterestore}</code>
  1346. * and <code>{@link Ext.grid.GridPanel#beforestatesave beforestatesave}</code>
  1347. * events in order to be stateful.
  1348. * </div></li>
  1349. * <li><b>Grid Changes</b> :
  1350. * <div class="sub-desc"><ul>
  1351. * <li>A <code>filters</code> <i>property</i> is added to the grid pointing to
  1352. * this plugin.</li>
  1353. * <li>A <code>filterupdate</code> <i>event</i> is added to the grid and is
  1354. * fired upon onStateChange completion.</li>
  1355. * </ul></div></li>
  1356. * <li><b>Server side code examples</b> :
  1357. * <div class="sub-desc"><ul>
  1358. * <li><a href="http://www.vinylfox.com/extjs/grid-filter-php-backend-code.php">PHP</a> - (Thanks VinylFox)</li>
  1359. * <li><a href="http://extjs.com/forum/showthread.php?p=77326#post77326">Ruby on Rails</a> - (Thanks Zyclops)</li>
  1360. * <li><a href="http://extjs.com/forum/showthread.php?p=176596#post176596">Ruby on Rails</a> - (Thanks Rotomaul)</li>
  1361. * <li><a href="http://www.debatablybeta.com/posts/using-extjss-grid-filtering-with-django/">Python</a> - (Thanks Matt)</li>
  1362. * <li><a href="http://mcantrell.wordpress.com/2008/08/22/extjs-grids-and-grails/">Grails</a> - (Thanks Mike)</li>
  1363. * </ul></div></li>
  1364. * </ul></div>
  1365. * <p><b><u>Example usage:</u></b></p>
  1366. * <pre><code>
  1367. var store = new Ext.data.GroupingStore({
  1368. ...
  1369. });
  1370. var filters = new Ext.ux.grid.GridFilters({
  1371. autoReload: false, //don&#39;t reload automatically
  1372. local: true, //only filter locally
  1373. // filters may be configured through the plugin,
  1374. // or in the column definition within the column model configuration
  1375. filters: [{
  1376. type: 'numeric',
  1377. dataIndex: 'id'
  1378. }, {
  1379. type: 'string',
  1380. dataIndex: 'name'
  1381. }, {
  1382. type: 'numeric',
  1383. dataIndex: 'price'
  1384. }, {
  1385. type: 'date',
  1386. dataIndex: 'dateAdded'
  1387. }, {
  1388. type: 'list',
  1389. dataIndex: 'size',
  1390. options: ['extra small', 'small', 'medium', 'large', 'extra large'],
  1391. phpMode: true
  1392. }, {
  1393. type: 'boolean',
  1394. dataIndex: 'visible'
  1395. }]
  1396. });
  1397. var cm = new Ext.grid.ColumnModel([{
  1398. ...
  1399. }]);
  1400. var grid = new Ext.grid.GridPanel({
  1401. ds: store,
  1402. cm: cm,
  1403. view: new Ext.grid.GroupingView(),
  1404. plugins: [filters],
  1405. height: 400,
  1406. width: 700,
  1407. bbar: new Ext.PagingToolbar({
  1408. store: store,
  1409. pageSize: 15,
  1410. plugins: [filters] //reset page to page 1 if filters change
  1411. })
  1412. });
  1413. store.load({params: {start: 0, limit: 15}});
  1414. // a filters property is added to the grid
  1415. grid.filters
  1416. * </code></pre>
  1417. */
  1418. Ext.ux.grid.GridFilters = Ext.extend(Ext.util.Observable, {
  1419. /**
  1420. * @cfg {Boolean} autoReload
  1421. * Defaults to true, reloading the datasource when a filter change happens.
  1422. * Set this to false to prevent the datastore from being reloaded if there
  1423. * are changes to the filters. See <code>{@link updateBuffer}</code>.
  1424. */
  1425. autoReload : true,
  1426. /**
  1427. * @cfg {Boolean} encode
  1428. * Specify true for {@link #buildQuery} to use Ext.util.JSON.encode to
  1429. * encode the filter query parameter sent with a remote request.
  1430. * Defaults to false.
  1431. */
  1432. /**
  1433. * @cfg {Array} filters
  1434. * An Array of filters config objects. Refer to each filter type class for
  1435. * configuration details specific to each filter type. Filters for Strings,
  1436. * Numeric Ranges, Date Ranges, Lists, and Boolean are the standard filters
  1437. * available.
  1438. */
  1439. /**
  1440. * @cfg {String} filterCls
  1441. * The css class to be applied to column headers with active filters.
  1442. * Defaults to <tt>'ux-filterd-column'</tt>.
  1443. */
  1444. filterCls : 'ux-filtered-column',
  1445. /**
  1446. * @cfg {Boolean} local
  1447. * <tt>true</tt> to use Ext.data.Store filter functions (local filtering)
  1448. * instead of the default (<tt>false</tt>) server side filtering.
  1449. */
  1450. local : false,
  1451. /**
  1452. * @cfg {String} menuFilterText
  1453. * defaults to <tt>'Filters'</tt>.
  1454. */
  1455. menuFilterText : 'Filters',
  1456. /**
  1457. * @cfg {String} paramPrefix
  1458. * The url parameter prefix for the filters.
  1459. * Defaults to <tt>'filter'</tt>.
  1460. */
  1461. paramPrefix : 'filter',
  1462. /**
  1463. * @cfg {Boolean} showMenu
  1464. * Defaults to true, including a filter submenu in the default header menu.
  1465. */
  1466. showMenu : true,
  1467. /**
  1468. * @cfg {String} stateId
  1469. * Name of the value to be used to store state information.
  1470. */
  1471. stateId : undefined,
  1472. /**
  1473. * @cfg {Integer} updateBuffer
  1474. * Number of milliseconds to defer store updates since the last filter change.
  1475. */
  1476. updateBuffer : 500,
  1477. /** @private */
  1478. constructor : function (config) {
  1479. config = config || {};
  1480. this.deferredUpdate = new Ext.util.DelayedTask(this.reload, this);
  1481. this.filters = new Ext.util.MixedCollection();
  1482. this.filters.getKey = function (o) {
  1483. return o ? o.dataIndex : null;
  1484. };
  1485. this.addFilters(config.filters);
  1486. delete config.filters;
  1487. Ext.apply(this, config);
  1488. },
  1489. /** @private */
  1490. init : function (grid) {
  1491. if (grid instanceof Ext.grid.GridPanel) {
  1492. this.grid = grid;
  1493. this.bindStore(this.grid.getStore(), true);
  1494. // assumes no filters were passed in the constructor, so try and use ones from the colModel
  1495. if(this.filters.getCount() == 0){
  1496. this.addFilters(this.grid.getColumnModel());
  1497. }
  1498. this.grid.filters = this;
  1499. this.grid.addEvents({'filterupdate': true});
  1500. grid.on({
  1501. scope: this,
  1502. beforestaterestore: this.applyState,
  1503. beforestatesave: this.saveState,
  1504. beforedestroy: this.destroy,
  1505. reconfigure: this.onReconfigure
  1506. });
  1507. if (grid.rendered){
  1508. this.onRender();
  1509. } else {
  1510. grid.on({
  1511. scope: this,
  1512. single: true,
  1513. render: this.onRender
  1514. });
  1515. }
  1516. } else if (grid instanceof Ext.PagingToolbar) {
  1517. this.toolbar = grid;
  1518. }
  1519. },
  1520. /**
  1521. * @private
  1522. * Handler for the grid's beforestaterestore event (fires before the state of the
  1523. * grid is restored).
  1524. * @param {Object} grid The grid object
  1525. * @param {Object} state The hash of state values returned from the StateProvider.
  1526. */
  1527. applyState : function (grid, state) {
  1528. var key, filter;
  1529. this.applyingState = true;
  1530. this.clearFilters();
  1531. if (state.filters) {
  1532. for (key in state.filters) {
  1533. filter = this.filters.get(key);
  1534. if (filter) {
  1535. filter.setValue(state.filters[key]);
  1536. filter.setActive(true);
  1537. }
  1538. }
  1539. }
  1540. this.deferredUpdate.cancel();
  1541. if (this.local) {
  1542. this.reload();
  1543. }
  1544. delete this.applyingState;
  1545. delete state.filters;
  1546. },
  1547. /**
  1548. * Saves the state of all active filters
  1549. * @param {Object} grid
  1550. * @param {Object} state
  1551. * @return {Boolean}
  1552. */
  1553. saveState : function (grid, state) {
  1554. var filters = {};
  1555. this.filters.each(function (filter) {
  1556. if (filter.active) {
  1557. filters[filter.dataIndex] = filter.getValue();
  1558. }
  1559. });
  1560. return (state.filters = filters);
  1561. },
  1562. /**
  1563. * @private
  1564. * Handler called when the grid is rendered
  1565. */
  1566. onRender : function () {
  1567. this.grid.getView().on('refresh', this.onRefresh, this);
  1568. this.createMenu();
  1569. },
  1570. /**
  1571. * @private
  1572. * Handler called by the grid 'beforedestroy' event
  1573. */
  1574. destroy : function () {
  1575. this.removeAll();
  1576. this.purgeListeners();
  1577. if(this.filterMenu){
  1578. Ext.menu.MenuMgr.unregister(this.filterMenu);
  1579. this.filterMenu.destroy();
  1580. this.filterMenu = this.menu.menu = null;
  1581. }
  1582. },
  1583. /**
  1584. * Remove all filters, permanently destroying them.
  1585. */
  1586. removeAll : function () {
  1587. if(this.filters){
  1588. Ext.destroy.apply(Ext, this.filters.items);
  1589. // remove all items from the collection
  1590. this.filters.clear();
  1591. }
  1592. },
  1593. /**
  1594. * Changes the data store bound to this view and refreshes it.
  1595. * @param {Store} store The store to bind to this view
  1596. */
  1597. bindStore : function(store, initial){
  1598. if(!initial && this.store){
  1599. if (this.local) {
  1600. store.un('load', this.onLoad, this);
  1601. } else {
  1602. store.un('beforeload', this.onBeforeLoad, this);
  1603. }
  1604. }
  1605. if(store){
  1606. if (this.local) {
  1607. store.on('load', this.onLoad, this);
  1608. } else {
  1609. store.on('beforeload', this.onBeforeLoad, this);
  1610. }
  1611. }
  1612. this.store = store;
  1613. },
  1614. /**
  1615. * @private
  1616. * Handler called when the grid reconfigure event fires
  1617. */
  1618. onReconfigure : function () {
  1619. this.bindStore(this.grid.getStore());
  1620. this.store.clearFilter();
  1621. this.removeAll();
  1622. this.addFilters(this.grid.getColumnModel());
  1623. this.updateColumnHeadings();
  1624. },
  1625. createMenu : function () {
  1626. var view = this.grid.getView(),
  1627. hmenu = view.hmenu;
  1628. if (this.showMenu && hmenu) {
  1629. this.sep = hmenu.addSeparator();
  1630. this.filterMenu = new Ext.menu.Menu({
  1631. id: this.grid.id + '-filters-menu'
  1632. });
  1633. this.menu = hmenu.add({
  1634. checked: false,
  1635. itemId: 'filters',
  1636. text: this.menuFilterText,
  1637. menu: this.filterMenu
  1638. });
  1639. this.menu.on({
  1640. scope: this,
  1641. checkchange: this.onCheckChange,
  1642. beforecheckchange: this.onBeforeCheck
  1643. });
  1644. hmenu.on('beforeshow', this.onMenu, this);
  1645. }
  1646. this.updateColumnHeadings();
  1647. },
  1648. /**
  1649. * @private
  1650. * Get the filter menu from the filters MixedCollection based on the clicked header
  1651. */
  1652. getMenuFilter : function () {
  1653. var view = this.grid.getView();
  1654. if (!view || view.hdCtxIndex === undefined) {
  1655. return null;
  1656. }
  1657. return this.filters.get(
  1658. view.cm.config[view.hdCtxIndex].dataIndex
  1659. );
  1660. },
  1661. /**
  1662. * @private
  1663. * Handler called by the grid's hmenu beforeshow event
  1664. */
  1665. onMenu : function (filterMenu) {
  1666. var filter = this.getMenuFilter();
  1667. if (filter) {
  1668. /*
  1669. TODO: lazy rendering
  1670. if (!filter.menu) {
  1671. filter.menu = filter.createMenu();
  1672. }
  1673. */
  1674. this.menu.menu = filter.menu;
  1675. this.menu.setChecked(filter.active, false);
  1676. // disable the menu if filter.disabled explicitly set to true
  1677. this.menu.setDisabled(filter.disabled === true);
  1678. }
  1679. this.menu.setVisible(filter !== undefined);
  1680. this.sep.setVisible(filter !== undefined);
  1681. },
  1682. /** @private */
  1683. onCheckChange : function (item, value) {
  1684. this.getMenuFilter().setActive(value);
  1685. },
  1686. /** @private */
  1687. onBeforeCheck : function (check, value) {
  1688. return !value || this.getMenuFilter().isActivatable();
  1689. },
  1690. /**
  1691. * @private
  1692. * Handler for all events on filters.
  1693. * @param {String} event Event name
  1694. * @param {Object} filter Standard signature of the event before the event is fired
  1695. */
  1696. onStateChange : function (event, filter) {
  1697. if (event === 'serialize') {
  1698. return;
  1699. }
  1700. if (filter == this.getMenuFilter()) {
  1701. this.menu.setChecked(filter.active, false);
  1702. }
  1703. if ((this.autoReload || this.local) && !this.applyingState) {
  1704. this.deferredUpdate.delay(this.updateBuffer);
  1705. }
  1706. this.updateColumnHeadings();
  1707. if (!this.applyingState) {
  1708. this.grid.saveState();
  1709. }
  1710. this.grid.fireEvent('filterupdate', this, filter);
  1711. },
  1712. /**
  1713. * @private
  1714. * Handler for store's beforeload event when configured for remote filtering
  1715. * @param {Object} store
  1716. * @param {Object} options
  1717. */
  1718. onBeforeLoad : function (store, options) {
  1719. options.params = options.params || {};
  1720. this.cleanParams(options.params);
  1721. var params = this.buildQuery(this.getFilterData());
  1722. Ext.apply(options.params, params);
  1723. },
  1724. /**
  1725. * @private
  1726. * Handler for store's load event when configured for local filtering
  1727. * @param {Object} store
  1728. * @param {Object} options
  1729. */
  1730. onLoad : function (store, options) {
  1731. store.filterBy(this.getRecordFilter());
  1732. },
  1733. /**
  1734. * @private
  1735. * Handler called when the grid's view is refreshed
  1736. */
  1737. onRefresh : function () {
  1738. this.updateColumnHeadings();
  1739. },
  1740. /**
  1741. * Update the styles for the header row based on the active filters
  1742. */
  1743. updateColumnHeadings : function () {
  1744. var view = this.grid.getView(),
  1745. i, len, filter;
  1746. if (view.mainHd) {
  1747. for (i = 0, len = view.cm.config.length; i < len; i++) {
  1748. filter = this.getFilter(view.cm.config[i].dataIndex);
  1749. Ext.fly(view.getHeaderCell(i))[filter && filter.active ? 'addClass' : 'removeClass'](this.filterCls);
  1750. }
  1751. }
  1752. },
  1753. /** @private */
  1754. reload : function () {
  1755. if (this.local) {
  1756. this.grid.store.clearFilter(true);
  1757. this.grid.store.filterBy(this.getRecordFilter());
  1758. } else {
  1759. var start,
  1760. store = this.grid.store;
  1761. this.deferredUpdate.cancel();
  1762. if (this.toolbar) {
  1763. start = store.paramNames.start;
  1764. if (store.lastOptions && store.lastOptions.params && store.lastOptions.params[start]) {
  1765. store.lastOptions.params[start] = 0;
  1766. }
  1767. }
  1768. store.reload();
  1769. }
  1770. },
  1771. /**
  1772. * Method factory that generates a record validator for the filters active at the time
  1773. * of invokation.
  1774. * @private
  1775. */
  1776. getRecordFilter : function () {
  1777. var f = [], len, i;
  1778. this.filters.each(function (filter) {
  1779. if (filter.active) {
  1780. f.push(filter);
  1781. }
  1782. });
  1783. len = f.length;
  1784. return function (record) {
  1785. for (i = 0; i < len; i++) {
  1786. if (!f[i].validateRecord(record)) {
  1787. return false;
  1788. }
  1789. }
  1790. return true;
  1791. };
  1792. },
  1793. /**
  1794. * Adds a filter to the collection and observes it for state change.
  1795. * @param {Object/Ext.ux.grid.filter.Filter} config A filter configuration or a filter object.
  1796. * @return {Ext.ux.grid.filter.Filter} The existing or newly created filter object.
  1797. */
  1798. addFilter : function (config) {
  1799. var Cls = this.getFilterClass(config.type),
  1800. filter = config.menu ? config : (new Cls(config));
  1801. this.filters.add(filter);
  1802. Ext.util.Observable.capture(filter, this.onStateChange, this);
  1803. return filter;
  1804. },
  1805. /**
  1806. * Adds filters to the collection.
  1807. * @param {Array/Ext.grid.ColumnModel} filters Either an Array of
  1808. * filter configuration objects or an Ext.grid.ColumnModel. The columns
  1809. * of a passed Ext.grid.ColumnModel will be examined for a <code>filter</code>
  1810. * property and, if present, will be used as the filter configuration object.
  1811. */
  1812. addFilters : function (filters) {
  1813. if (filters) {
  1814. var i, len, filter, cm = false, dI;
  1815. if (filters instanceof Ext.grid.ColumnModel) {
  1816. filters = filters.config;
  1817. cm = true;
  1818. }
  1819. for (i = 0, len = filters.length; i < len; i++) {
  1820. filter = false;
  1821. if (cm) {
  1822. dI = filters[i].dataIndex;
  1823. filter = filters[i].filter || filters[i].filterable;
  1824. if (filter){
  1825. filter = (filter === true) ? {} : filter;
  1826. Ext.apply(filter, {dataIndex:dI});
  1827. // filter type is specified in order of preference:
  1828. // filter type specified in config
  1829. // type specified in store's field's type config
  1830. filter.type = filter.type || this.store.fields.get(dI).type.type;
  1831. }
  1832. } else {
  1833. filter = filters[i];
  1834. }
  1835. // if filter config found add filter for the column
  1836. if (filter) {
  1837. this.addFilter(filter);
  1838. }
  1839. }
  1840. }
  1841. },
  1842. /**
  1843. * Returns a filter for the given dataIndex, if one exists.
  1844. * @param {String} dataIndex The dataIndex of the desired filter object.
  1845. * @return {Ext.ux.grid.filter.Filter}
  1846. */
  1847. getFilter : function (dataIndex) {
  1848. return this.filters.get(dataIndex);
  1849. },
  1850. /**
  1851. * Turns all filters off. This does not clear the configuration information
  1852. * (see {@link #removeAll}).
  1853. */
  1854. clearFilters : function () {
  1855. this.filters.each(function (filter) {
  1856. filter.setActive(false);
  1857. });
  1858. },
  1859. /**
  1860. * Returns an Array of the currently active filters.
  1861. * @return {Array} filters Array of the currently active filters.
  1862. */
  1863. getFilterData : function () {
  1864. var filters = [], i, len;
  1865. this.filters.each(function (f) {
  1866. if (f.active) {
  1867. var d = [].concat(f.serialize());
  1868. for (i = 0, len = d.length; i < len; i++) {
  1869. filters.push({
  1870. field: f.dataIndex,
  1871. data: d[i]
  1872. });
  1873. }
  1874. }
  1875. });
  1876. return filters;
  1877. },
  1878. /**
  1879. * Function to take the active filters data and build it into a query.
  1880. * The format of the query depends on the <code>{@link #encode}</code>
  1881. * configuration:
  1882. * <div class="mdetail-params"><ul>
  1883. *
  1884. * <li><b><tt>false</tt></b> : <i>Default</i>
  1885. * <div class="sub-desc">
  1886. * Flatten into query string of the form (assuming <code>{@link #paramPrefix}='filters'</code>:
  1887. * <pre><code>
  1888. filters[0][field]="someDataIndex"&
  1889. filters[0][data][comparison]="someValue1"&
  1890. filters[0][data][type]="someValue2"&
  1891. filters[0][data][value]="someValue3"&
  1892. * </code></pre>
  1893. * </div></li>
  1894. * <li><b><tt>true</tt></b> :
  1895. * <div class="sub-desc">
  1896. * JSON encode the filter data
  1897. * <pre><code>
  1898. filters[0][field]="someDataIndex"&
  1899. filters[0][data][comparison]="someValue1"&
  1900. filters[0][data][type]="someValue2"&
  1901. filters[0][data][value]="someValue3"&
  1902. * </code></pre>
  1903. * </div></li>
  1904. * </ul></div>
  1905. * Override this method to customize the format of the filter query for remote requests.
  1906. * @param {Array} filters A collection of objects representing active filters and their configuration.
  1907. * Each element will take the form of {field: dataIndex, data: filterConf}. dataIndex is not assured
  1908. * to be unique as any one filter may be a composite of more basic filters for the same dataIndex.
  1909. * @return {Object} Query keys and values
  1910. */
  1911. buildQuery : function (filters) {
  1912. var p = {}, i, f, root, dataPrefix, key, tmp,
  1913. len = filters.length;
  1914. if (!this.encode){
  1915. for (i = 0; i < len; i++) {
  1916. f = filters[i];
  1917. root = [this.paramPrefix, '[', i, ']'].join('');
  1918. p[root + '[field]'] = f.field;
  1919. dataPrefix = root + '[data]';
  1920. for (key in f.data) {
  1921. p[[dataPrefix, '[', key, ']'].join('')] = f.data[key];
  1922. }
  1923. }
  1924. } else {
  1925. tmp = [];
  1926. for (i = 0; i < len; i++) {
  1927. f = filters[i];
  1928. tmp.push(Ext.apply(
  1929. {},
  1930. {field: f.field},
  1931. f.data
  1932. ));
  1933. }
  1934. // only build if there is active filter
  1935. if (tmp.length > 0){
  1936. p[this.paramPrefix] = Ext.util.JSON.encode(tmp);
  1937. }
  1938. }
  1939. return p;
  1940. },
  1941. /**
  1942. * Removes filter related query parameters from the provided object.
  1943. * @param {Object} p Query parameters that may contain filter related fields.
  1944. */
  1945. cleanParams : function (p) {
  1946. // if encoding just delete the property
  1947. if (this.encode) {
  1948. delete p[this.paramPrefix];
  1949. // otherwise scrub the object of filter data
  1950. } else {
  1951. var regex, key;
  1952. regex = new RegExp('^' + this.paramPrefix + '\[[0-9]+\]');
  1953. for (key in p) {
  1954. if (regex.test(key)) {
  1955. delete p[key];
  1956. }
  1957. }
  1958. }
  1959. },
  1960. /**
  1961. * Function for locating filter classes, overwrite this with your favorite
  1962. * loader to provide dynamic filter loading.
  1963. * @param {String} type The type of filter to load ('Filter' is automatically
  1964. * appended to the passed type; eg, 'string' becomes 'StringFilter').
  1965. * @return {Class} The Ext.ux.grid.filter.Class
  1966. */
  1967. getFilterClass : function (type) {
  1968. // map the supported Ext.data.Field type values into a supported filter
  1969. switch(type) {
  1970. case 'auto':
  1971. type = 'string';
  1972. break;
  1973. case 'int':
  1974. case 'float':
  1975. type = 'numeric';
  1976. break;
  1977. case 'bool':
  1978. type = 'boolean';
  1979. break;
  1980. }
  1981. return Ext.ux.grid.filter[type.substr(0, 1).toUpperCase() + type.substr(1) + 'Filter'];
  1982. }
  1983. });
  1984. // register ptype
  1985. Ext.preg('gridfilters', Ext.ux.grid.GridFilters);
  1986. Ext.namespace('Ext.ux.grid.filter');
  1987. /**
  1988. * @class Ext.ux.grid.filter.Filter
  1989. * @extends Ext.util.Observable
  1990. * Abstract base class for filter implementations.
  1991. */
  1992. Ext.ux.grid.filter.Filter = Ext.extend(Ext.util.Observable, {
  1993. /**
  1994. * @cfg {Boolean} active
  1995. * Indicates the initial status of the filter (defaults to false).
  1996. */
  1997. active : false,
  1998. /**
  1999. * True if this filter is active. Use setActive() to alter after configuration.
  2000. * @type Boolean
  2001. * @property active
  2002. */
  2003. /**
  2004. * @cfg {String} dataIndex
  2005. * The {@link Ext.data.Store} dataIndex of the field this filter represents.
  2006. * The dataIndex does not actually have to exist in the store.
  2007. */
  2008. dataIndex : null,
  2009. /**
  2010. * The filter configuration menu that will be installed into the filter submenu of a column menu.
  2011. * @type Ext.menu.Menu
  2012. * @property
  2013. */
  2014. menu : null,
  2015. /**
  2016. * @cfg {Number} updateBuffer
  2017. * Number of milliseconds to wait after user interaction to fire an update. Only supported
  2018. * by filters: 'list', 'numeric', and 'string'. Defaults to 500.
  2019. */
  2020. updateBuffer : 500,
  2021. constructor : function (config) {
  2022. Ext.apply(this, config);
  2023. this.addEvents(
  2024. /**
  2025. * @event activate
  2026. * Fires when an inactive filter becomes active
  2027. * @param {Ext.ux.grid.filter.Filter} this
  2028. */
  2029. 'activate',
  2030. /**
  2031. * @event deactivate
  2032. * Fires when an active filter becomes inactive
  2033. * @param {Ext.ux.grid.filter.Filter} this
  2034. */
  2035. 'deactivate',
  2036. /**
  2037. * @event serialize
  2038. * Fires after the serialization process. Use this to attach additional parameters to serialization
  2039. * data before it is encoded and sent to the server.
  2040. * @param {Array/Object} data A map or collection of maps representing the current filter configuration.
  2041. * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.
  2042. */
  2043. 'serialize',
  2044. /**
  2045. * @event update
  2046. * Fires when a filter configuration has changed
  2047. * @param {Ext.ux.grid.filter.Filter} this The filter object.
  2048. */
  2049. 'update'
  2050. );
  2051. Ext.ux.grid.filter.Filter.superclass.constructor.call(this);
  2052. this.menu = new Ext.menu.Menu();
  2053. this.init(config);
  2054. if(config && config.value){
  2055. this.setValue(config.value);
  2056. this.setActive(config.active !== false, true);
  2057. delete config.value;
  2058. }
  2059. },
  2060. /**
  2061. * Destroys this filter by purging any event listeners, and removing any menus.
  2062. */
  2063. destroy : function(){
  2064. if (this.menu){
  2065. this.menu.destroy();
  2066. }
  2067. this.purgeListeners();
  2068. },
  2069. /**
  2070. * Template method to be implemented by all subclasses that is to
  2071. * initialize the filter and install required menu items.
  2072. * Defaults to Ext.emptyFn.
  2073. */
  2074. init : Ext.emptyFn,
  2075. /**
  2076. * Template method to be implemented by all subclasses that is to
  2077. * get and return the value of the filter.
  2078. * Defaults to Ext.emptyFn.
  2079. * @return {Object} The 'serialized' form of this filter
  2080. * @methodOf Ext.ux.grid.filter.Filter
  2081. */
  2082. getValue : Ext.emptyFn,
  2083. /**
  2084. * Template method to be implemented by all subclasses that is to
  2085. * set the value of the filter and fire the 'update' event.
  2086. * Defaults to Ext.emptyFn.
  2087. * @param {Object} data The value to set the filter
  2088. * @methodOf Ext.ux.grid.filter.Filter
  2089. */
  2090. setValue : Ext.emptyFn,
  2091. /**
  2092. * Template method to be implemented by all subclasses that is to
  2093. * return <tt>true</tt> if the filter has enough configuration information to be activated.
  2094. * Defaults to <tt>return true</tt>.
  2095. * @return {Boolean}
  2096. */
  2097. isActivatable : function(){
  2098. return true;
  2099. },
  2100. /**
  2101. * Template method to be implemented by all subclasses that is to
  2102. * get and return serialized filter data for transmission to the server.
  2103. * Defaults to Ext.emptyFn.
  2104. */
  2105. getSerialArgs : Ext.emptyFn,
  2106. /**
  2107. * Template method to be implemented by all subclasses that is to
  2108. * validates the provided Ext.data.Record against the filters configuration.
  2109. * Defaults to <tt>return true</tt>.
  2110. * @param {Ext.data.Record} record The record to validate
  2111. * @return {Boolean} true if the record is valid within the bounds
  2112. * of the filter, false otherwise.
  2113. */
  2114. validateRecord : function(){
  2115. return true;
  2116. },
  2117. /**
  2118. * Returns the serialized filter data for transmission to the server
  2119. * and fires the 'serialize' event.
  2120. * @return {Object/Array} An object or collection of objects containing
  2121. * key value pairs representing the current configuration of the filter.
  2122. * @methodOf Ext.ux.grid.filter.Filter
  2123. */
  2124. serialize : function(){
  2125. var args = this.getSerialArgs();
  2126. this.fireEvent('serialize', args, this);
  2127. return args;
  2128. },
  2129. /** @private */
  2130. fireUpdate : function(){
  2131. if (this.active) {
  2132. this.fireEvent('update', this);
  2133. }
  2134. this.setActive(this.isActivatable());
  2135. },
  2136. /**
  2137. * Sets the status of the filter and fires the appropriate events.
  2138. * @param {Boolean} active The new filter state.
  2139. * @param {Boolean} suppressEvent True to prevent events from being fired.
  2140. * @methodOf Ext.ux.grid.filter.Filter
  2141. */
  2142. setActive : function(active, suppressEvent){
  2143. if(this.active != active){
  2144. this.active = active;
  2145. if (suppressEvent !== true) {
  2146. this.fireEvent(active ? 'activate' : 'deactivate', this);
  2147. }
  2148. }
  2149. }
  2150. });/**
  2151. * @class Ext.ux.grid.filter.BooleanFilter
  2152. * @extends Ext.ux.grid.filter.Filter
  2153. * Boolean filters use unique radio group IDs (so you can have more than one!)
  2154. * <p><b><u>Example Usage:</u></b></p>
  2155. * <pre><code>
  2156. var filters = new Ext.ux.grid.GridFilters({
  2157. ...
  2158. filters: [{
  2159. // required configs
  2160. type: 'boolean',
  2161. dataIndex: 'visible'
  2162. // optional configs
  2163. defaultValue: null, // leave unselected (false selected by default)
  2164. yesText: 'Yes', // default
  2165. noText: 'No' // default
  2166. }]
  2167. });
  2168. * </code></pre>
  2169. */
  2170. Ext.ux.grid.filter.BooleanFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
  2171. /**
  2172. * @cfg {Boolean} defaultValue
  2173. * Set this to null if you do not want either option to be checked by default. Defaults to false.
  2174. */
  2175. defaultValue : false,
  2176. /**
  2177. * @cfg {String} yesText
  2178. * Defaults to 'Yes'.
  2179. */
  2180. yesText : 'Yes',
  2181. /**
  2182. * @cfg {String} noText
  2183. * Defaults to 'No'.
  2184. */
  2185. noText : 'No',
  2186. /**
  2187. * @private
  2188. * Template method that is to initialize the filter and install required menu items.
  2189. */
  2190. init : function (config) {
  2191. var gId = Ext.id();
  2192. this.options = [
  2193. new Ext.menu.CheckItem({text: this.yesText, group: gId, checked: this.defaultValue === true}),
  2194. new Ext.menu.CheckItem({text: this.noText, group: gId, checked: this.defaultValue === false})];
  2195. this.menu.add(this.options[0], this.options[1]);
  2196. for(var i=0; i<this.options.length; i++){
  2197. this.options[i].on('click', this.fireUpdate, this);
  2198. this.options[i].on('checkchange', this.fireUpdate, this);
  2199. }
  2200. },
  2201. /**
  2202. * @private
  2203. * Template method that is to get and return the value of the filter.
  2204. * @return {String} The value of this filter
  2205. */
  2206. getValue : function () {
  2207. return this.options[0].checked;
  2208. },
  2209. /**
  2210. * @private
  2211. * Template method that is to set the value of the filter.
  2212. * @param {Object} value The value to set the filter
  2213. */
  2214. setValue : function (value) {
  2215. this.options[value ? 0 : 1].setChecked(true);
  2216. },
  2217. /**
  2218. * @private
  2219. * Template method that is to get and return serialized filter data for
  2220. * transmission to the server.
  2221. * @return {Object/Array} An object or collection of objects containing
  2222. * key value pairs representing the current configuration of the filter.
  2223. */
  2224. getSerialArgs : function () {
  2225. var args = {type: 'boolean', value: this.getValue()};
  2226. return args;
  2227. },
  2228. /**
  2229. * Template method that is to validate the provided Ext.data.Record
  2230. * against the filters configuration.
  2231. * @param {Ext.data.Record} record The record to validate
  2232. * @return {Boolean} true if the record is valid within the bounds
  2233. * of the filter, false otherwise.
  2234. */
  2235. validateRecord : function (record) {
  2236. return record.get(this.dataIndex) == this.getValue();
  2237. }
  2238. });/**
  2239. * @class Ext.ux.grid.filter.DateFilter
  2240. * @extends Ext.ux.grid.filter.Filter
  2241. * Filter by a configurable Ext.menu.DateMenu
  2242. * <p><b><u>Example Usage:</u></b></p>
  2243. * <pre><code>
  2244. var filters = new Ext.ux.grid.GridFilters({
  2245. ...
  2246. filters: [{
  2247. // required configs
  2248. type: 'date',
  2249. dataIndex: 'dateAdded',
  2250. // optional configs
  2251. dateFormat: 'm/d/Y', // default
  2252. beforeText: 'Before', // default
  2253. afterText: 'After', // default
  2254. onText: 'On', // default
  2255. pickerOpts: {
  2256. // any DateMenu configs
  2257. },
  2258. active: true // default is false
  2259. }]
  2260. });
  2261. * </code></pre>
  2262. */
  2263. Ext.ux.grid.filter.DateFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
  2264. /**
  2265. * @cfg {String} afterText
  2266. * Defaults to 'After'.
  2267. */
  2268. afterText : 'After',
  2269. /**
  2270. * @cfg {String} beforeText
  2271. * Defaults to 'Before'.
  2272. */
  2273. beforeText : 'Before',
  2274. /**
  2275. * @cfg {Object} compareMap
  2276. * Map for assigning the comparison values used in serialization.
  2277. */
  2278. compareMap : {
  2279. before: 'lt',
  2280. after: 'gt',
  2281. on: 'eq'
  2282. },
  2283. /**
  2284. * @cfg {String} dateFormat
  2285. * The date format to return when using getValue.
  2286. * Defaults to 'm/d/Y'.
  2287. */
  2288. dateFormat : 'm/d/Y',
  2289. /**
  2290. * @cfg {Date} maxDate
  2291. * Allowable date as passed to the Ext.DatePicker
  2292. * Defaults to undefined.
  2293. */
  2294. /**
  2295. * @cfg {Date} minDate
  2296. * Allowable date as passed to the Ext.DatePicker
  2297. * Defaults to undefined.
  2298. */
  2299. /**
  2300. * @cfg {Array} menuItems
  2301. * The items to be shown in this menu
  2302. * Defaults to:<pre>
  2303. * menuItems : ['before', 'after', '-', 'on'],
  2304. * </pre>
  2305. */
  2306. menuItems : ['before', 'after', '-', 'on'],
  2307. /**
  2308. * @cfg {Object} menuItemCfgs
  2309. * Default configuration options for each menu item
  2310. */
  2311. menuItemCfgs : {
  2312. selectOnFocus: true,
  2313. width: 125
  2314. },
  2315. /**
  2316. * @cfg {String} onText
  2317. * Defaults to 'On'.
  2318. */
  2319. onText : 'On',
  2320. /**
  2321. * @cfg {Object} pickerOpts
  2322. * Configuration options for the date picker associated with each field.
  2323. */
  2324. pickerOpts : {},
  2325. /**
  2326. * @private
  2327. * Template method that is to initialize the filter and install required menu items.
  2328. */
  2329. init : function (config) {
  2330. var menuCfg, i, len, item, cfg, Cls;
  2331. menuCfg = Ext.apply(this.pickerOpts, {
  2332. minDate: this.minDate,
  2333. maxDate: this.maxDate,
  2334. format: this.dateFormat,
  2335. listeners: {
  2336. scope: this,
  2337. select: this.onMenuSelect
  2338. }
  2339. });
  2340. this.fields = {};
  2341. for (i = 0, len = this.menuItems.length; i < len; i++) {
  2342. item = this.menuItems[i];
  2343. if (item !== '-') {
  2344. cfg = {
  2345. itemId: 'range-' + item,
  2346. text: this[item + 'Text'],
  2347. menu: new Ext.menu.DateMenu(
  2348. Ext.apply(menuCfg, {
  2349. itemId: item
  2350. })
  2351. ),
  2352. listeners: {
  2353. scope: this,
  2354. checkchange: this.onCheckChange
  2355. }
  2356. };
  2357. Cls = Ext.menu.CheckItem;
  2358. item = this.fields[item] = new Cls(cfg);
  2359. }
  2360. //this.add(item);
  2361. this.menu.add(item);
  2362. }
  2363. },
  2364. onCheckChange : function () {
  2365. this.setActive(this.isActivatable());
  2366. this.fireEvent('update', this);
  2367. },
  2368. /**
  2369. * @private
  2370. * Handler method called when there is a keyup event on an input
  2371. * item of this menu.
  2372. */
  2373. onInputKeyUp : function (field, e) {
  2374. var k = e.getKey();
  2375. if (k == e.RETURN && field.isValid()) {
  2376. e.stopEvent();
  2377. this.menu.hide(true);
  2378. return;
  2379. }
  2380. },
  2381. /**
  2382. * Handler for when the menu for a field fires the 'select' event
  2383. * @param {Object} date
  2384. * @param {Object} menuItem
  2385. * @param {Object} value
  2386. * @param {Object} picker
  2387. */
  2388. onMenuSelect : function (menuItem, value, picker) {
  2389. var fields = this.fields,
  2390. field = this.fields[menuItem.itemId];
  2391. field.setChecked(true);
  2392. if (field == fields.on) {
  2393. fields.before.setChecked(false, true);
  2394. fields.after.setChecked(false, true);
  2395. } else {
  2396. fields.on.setChecked(false, true);
  2397. if (field == fields.after && fields.before.menu.picker.value < value) {
  2398. fields.before.setChecked(false, true);
  2399. } else if (field == fields.before && fields.after.menu.picker.value > value) {
  2400. fields.after.setChecked(false, true);
  2401. }
  2402. }
  2403. this.fireEvent('update', this);
  2404. },
  2405. /**
  2406. * @private
  2407. * Template method that is to get and return the value of the filter.
  2408. * @return {String} The value of this filter
  2409. */
  2410. getValue : function () {
  2411. var key, result = {};
  2412. for (key in this.fields) {
  2413. if (this.fields[key].checked) {
  2414. result[key] = this.fields[key].menu.picker.getValue();
  2415. }
  2416. }
  2417. return result;
  2418. },
  2419. /**
  2420. * @private
  2421. * Template method that is to set the value of the filter.
  2422. * @param {Object} value The value to set the filter
  2423. * @param {Boolean} preserve true to preserve the checked status
  2424. * of the other fields. Defaults to false, unchecking the
  2425. * other fields
  2426. */
  2427. setValue : function (value, preserve) {
  2428. var key;
  2429. for (key in this.fields) {
  2430. if(value[key]){
  2431. this.fields[key].menu.picker.setValue(value[key]);
  2432. this.fields[key].setChecked(true);
  2433. } else if (!preserve) {
  2434. this.fields[key].setChecked(false);
  2435. }
  2436. }
  2437. this.fireEvent('update', this);
  2438. },
  2439. /**
  2440. * @private
  2441. * Template method that is to return <tt>true</tt> if the filter
  2442. * has enough configuration information to be activated.
  2443. * @return {Boolean}
  2444. */
  2445. isActivatable : function () {
  2446. var key;
  2447. for (key in this.fields) {
  2448. if (this.fields[key].checked) {
  2449. return true;
  2450. }
  2451. }
  2452. return false;
  2453. },
  2454. /**
  2455. * @private
  2456. * Template method that is to get and return serialized filter data for
  2457. * transmission to the server.
  2458. * @return {Object/Array} An object or collection of objects containing
  2459. * key value pairs representing the current configuration of the filter.
  2460. */
  2461. getSerialArgs : function () {
  2462. var args = [];
  2463. for (var key in this.fields) {
  2464. if(this.fields[key].checked){
  2465. args.push({
  2466. type: 'date',
  2467. comparison: this.compareMap[key],
  2468. value: this.getFieldValue(key).format(this.dateFormat)
  2469. });
  2470. }
  2471. }
  2472. return args;
  2473. },
  2474. /**
  2475. * Get and return the date menu picker value
  2476. * @param {String} item The field identifier ('before', 'after', 'on')
  2477. * @return {Date} Gets the current selected value of the date field
  2478. */
  2479. getFieldValue : function(item){
  2480. return this.fields[item].menu.picker.getValue();
  2481. },
  2482. /**
  2483. * Gets the menu picker associated with the passed field
  2484. * @param {String} item The field identifier ('before', 'after', 'on')
  2485. * @return {Object} The menu picker
  2486. */
  2487. getPicker : function(item){
  2488. return this.fields[item].menu.picker;
  2489. },
  2490. /**
  2491. * Template method that is to validate the provided Ext.data.Record
  2492. * against the filters configuration.
  2493. * @param {Ext.data.Record} record The record to validate
  2494. * @return {Boolean} true if the record is valid within the bounds
  2495. * of the filter, false otherwise.
  2496. */
  2497. validateRecord : function (record) {
  2498. var key,
  2499. pickerValue,
  2500. val = record.get(this.dataIndex);
  2501. if(!Ext.isDate(val)){
  2502. return false;
  2503. }
  2504. val = val.clearTime(true).getTime();
  2505. for (key in this.fields) {
  2506. if (this.fields[key].checked) {
  2507. pickerValue = this.getFieldValue(key).clearTime(true).getTime();
  2508. if (key == 'before' && pickerValue <= val) {
  2509. return false;
  2510. }
  2511. if (key == 'after' && pickerValue >= val) {
  2512. return false;
  2513. }
  2514. if (key == 'on' && pickerValue != val) {
  2515. return false;
  2516. }
  2517. }
  2518. }
  2519. return true;
  2520. }
  2521. });/**
  2522. * @class Ext.ux.grid.filter.ListFilter
  2523. * @extends Ext.ux.grid.filter.Filter
  2524. * <p>List filters are able to be preloaded/backed by an Ext.data.Store to load
  2525. * their options the first time they are shown. ListFilter utilizes the
  2526. * {@link Ext.ux.menu.ListMenu} component.</p>
  2527. * <p>Although not shown here, this class accepts all configuration options
  2528. * for {@link Ext.ux.menu.ListMenu}.</p>
  2529. *
  2530. * <p><b><u>Example Usage:</u></b></p>
  2531. * <pre><code>
  2532. var filters = new Ext.ux.grid.GridFilters({
  2533. ...
  2534. filters: [{
  2535. type: 'list',
  2536. dataIndex: 'size',
  2537. phpMode: true,
  2538. // options will be used as data to implicitly creates an ArrayStore
  2539. options: ['extra small', 'small', 'medium', 'large', 'extra large']
  2540. }]
  2541. });
  2542. * </code></pre>
  2543. *
  2544. */
  2545. Ext.ux.grid.filter.ListFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
  2546. /**
  2547. * @cfg {Array} options
  2548. * <p><code>data</code> to be used to implicitly create a data store
  2549. * to back this list when the data source is <b>local</b>. If the
  2550. * data for the list is remote, use the <code>{@link #store}</code>
  2551. * config instead.</p>
  2552. * <br><p>Each item within the provided array may be in one of the
  2553. * following formats:</p>
  2554. * <div class="mdetail-params"><ul>
  2555. * <li><b>Array</b> :
  2556. * <pre><code>
  2557. options: [
  2558. [11, 'extra small'],
  2559. [18, 'small'],
  2560. [22, 'medium'],
  2561. [35, 'large'],
  2562. [44, 'extra large']
  2563. ]
  2564. * </code></pre>
  2565. * </li>
  2566. * <li><b>Object</b> :
  2567. * <pre><code>
  2568. labelField: 'name', // override default of 'text'
  2569. options: [
  2570. {id: 11, name:'extra small'},
  2571. {id: 18, name:'small'},
  2572. {id: 22, name:'medium'},
  2573. {id: 35, name:'large'},
  2574. {id: 44, name:'extra large'}
  2575. ]
  2576. * </code></pre>
  2577. * </li>
  2578. * <li><b>String</b> :
  2579. * <pre><code>
  2580. * options: ['extra small', 'small', 'medium', 'large', 'extra large']
  2581. * </code></pre>
  2582. * </li>
  2583. */
  2584. /**
  2585. * @cfg {Boolean} phpMode
  2586. * <p>Adjust the format of this filter. Defaults to false.</p>
  2587. * <br><p>When GridFilters <code>@cfg encode = false</code> (default):</p>
  2588. * <pre><code>
  2589. // phpMode == false (default):
  2590. filter[0][data][type] list
  2591. filter[0][data][value] value1
  2592. filter[0][data][value] value2
  2593. filter[0][field] prod
  2594. // phpMode == true:
  2595. filter[0][data][type] list
  2596. filter[0][data][value] value1, value2
  2597. filter[0][field] prod
  2598. * </code></pre>
  2599. * When GridFilters <code>@cfg encode = true</code>:
  2600. * <pre><code>
  2601. // phpMode == false (default):
  2602. filter : [{"type":"list","value":["small","medium"],"field":"size"}]
  2603. // phpMode == true:
  2604. filter : [{"type":"list","value":"small,medium","field":"size"}]
  2605. * </code></pre>
  2606. */
  2607. phpMode : false,
  2608. /**
  2609. * @cfg {Ext.data.Store} store
  2610. * The {@link Ext.data.Store} this list should use as its data source
  2611. * when the data source is <b>remote</b>. If the data for the list
  2612. * is local, use the <code>{@link #options}</code> config instead.
  2613. */
  2614. /**
  2615. * @private
  2616. * Template method that is to initialize the filter and install required menu items.
  2617. * @param {Object} config
  2618. */
  2619. init : function (config) {
  2620. this.dt = new Ext.util.DelayedTask(this.fireUpdate, this);
  2621. // if a menu already existed, do clean up first
  2622. if (this.menu){
  2623. this.menu.destroy();
  2624. }
  2625. this.menu = new Ext.ux.menu.ListMenu(config);
  2626. this.menu.on('checkchange', this.onCheckChange, this);
  2627. },
  2628. /**
  2629. * @private
  2630. * Template method that is to get and return the value of the filter.
  2631. * @return {String} The value of this filter
  2632. */
  2633. getValue : function () {
  2634. return this.menu.getSelected();
  2635. },
  2636. /**
  2637. * @private
  2638. * Template method that is to set the value of the filter.
  2639. * @param {Object} value The value to set the filter
  2640. */
  2641. setValue : function (value) {
  2642. this.menu.setSelected(value);
  2643. this.fireEvent('update', this);
  2644. },
  2645. /**
  2646. * @private
  2647. * Template method that is to return <tt>true</tt> if the filter
  2648. * has enough configuration information to be activated.
  2649. * @return {Boolean}
  2650. */
  2651. isActivatable : function () {
  2652. return this.getValue().length > 0;
  2653. },
  2654. /**
  2655. * @private
  2656. * Template method that is to get and return serialized filter data for
  2657. * transmission to the server.
  2658. * @return {Object/Array} An object or collection of objects containing
  2659. * key value pairs representing the current configuration of the filter.
  2660. */
  2661. getSerialArgs : function () {
  2662. var args = {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
  2663. return args;
  2664. },
  2665. /** @private */
  2666. onCheckChange : function(){
  2667. this.dt.delay(this.updateBuffer);
  2668. },
  2669. /**
  2670. * Template method that is to validate the provided Ext.data.Record
  2671. * against the filters configuration.
  2672. * @param {Ext.data.Record} record The record to validate
  2673. * @return {Boolean} true if the record is valid within the bounds
  2674. * of the filter, false otherwise.
  2675. */
  2676. validateRecord : function (record) {
  2677. return this.getValue().indexOf(record.get(this.dataIndex)) > -1;
  2678. }
  2679. });/**
  2680. * @class Ext.ux.grid.filter.NumericFilter
  2681. * @extends Ext.ux.grid.filter.Filter
  2682. * Filters using an Ext.ux.menu.RangeMenu.
  2683. * <p><b><u>Example Usage:</u></b></p>
  2684. * <pre><code>
  2685. var filters = new Ext.ux.grid.GridFilters({
  2686. ...
  2687. filters: [{
  2688. type: 'numeric',
  2689. dataIndex: 'price'
  2690. }]
  2691. });
  2692. * </code></pre>
  2693. */
  2694. Ext.ux.grid.filter.NumericFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
  2695. /**
  2696. * @cfg {Object} fieldCls
  2697. * The Class to use to construct each field item within this menu
  2698. * Defaults to:<pre>
  2699. * fieldCls : Ext.form.NumberField
  2700. * </pre>
  2701. */
  2702. fieldCls : Ext.form.NumberField,
  2703. /**
  2704. * @cfg {Object} fieldCfg
  2705. * The default configuration options for any field item unless superseded
  2706. * by the <code>{@link #fields}</code> configuration.
  2707. * Defaults to:<pre>
  2708. * fieldCfg : {}
  2709. * </pre>
  2710. * Example usage:
  2711. * <pre><code>
  2712. fieldCfg : {
  2713. width: 150,
  2714. },
  2715. * </code></pre>
  2716. */
  2717. /**
  2718. * @cfg {Object} fields
  2719. * The field items may be configured individually
  2720. * Defaults to <tt>undefined</tt>.
  2721. * Example usage:
  2722. * <pre><code>
  2723. fields : {
  2724. gt: { // override fieldCfg options
  2725. width: 200,
  2726. fieldCls: Ext.ux.form.CustomNumberField // to override default {@link #fieldCls}
  2727. }
  2728. },
  2729. * </code></pre>
  2730. */
  2731. /**
  2732. * @cfg {Object} iconCls
  2733. * The iconCls to be applied to each comparator field item.
  2734. * Defaults to:<pre>
  2735. iconCls : {
  2736. gt : 'ux-rangemenu-gt',
  2737. lt : 'ux-rangemenu-lt',
  2738. eq : 'ux-rangemenu-eq'
  2739. }
  2740. * </pre>
  2741. */
  2742. iconCls : {
  2743. gt : 'ux-rangemenu-gt',
  2744. lt : 'ux-rangemenu-lt',
  2745. eq : 'ux-rangemenu-eq'
  2746. },
  2747. /**
  2748. * @cfg {Object} menuItemCfgs
  2749. * Default configuration options for each menu item
  2750. * Defaults to:<pre>
  2751. menuItemCfgs : {
  2752. emptyText: 'Enter Filter Text...',
  2753. selectOnFocus: true,
  2754. width: 125
  2755. }
  2756. * </pre>
  2757. */
  2758. menuItemCfgs : {
  2759. emptyText: 'Enter Filter Text...',
  2760. selectOnFocus: true,
  2761. width: 125
  2762. },
  2763. /**
  2764. * @cfg {Array} menuItems
  2765. * The items to be shown in this menu. Items are added to the menu
  2766. * according to their position within this array. Defaults to:<pre>
  2767. * menuItems : ['lt','gt','-','eq']
  2768. * </pre>
  2769. */
  2770. menuItems : ['lt', 'gt', '-', 'eq'],
  2771. /**
  2772. * @private
  2773. * Template method that is to initialize the filter and install required menu items.
  2774. */
  2775. init : function (config) {
  2776. // if a menu already existed, do clean up first
  2777. if (this.menu){
  2778. this.menu.destroy();
  2779. }
  2780. this.menu = new Ext.ux.menu.RangeMenu(Ext.apply(config, {
  2781. // pass along filter configs to the menu
  2782. fieldCfg : this.fieldCfg || {},
  2783. fieldCls : this.fieldCls,
  2784. fields : this.fields || {},
  2785. iconCls: this.iconCls,
  2786. menuItemCfgs: this.menuItemCfgs,
  2787. menuItems: this.menuItems,
  2788. updateBuffer: this.updateBuffer
  2789. }));
  2790. // relay the event fired by the menu
  2791. this.menu.on('update', this.fireUpdate, this);
  2792. },
  2793. /**
  2794. * @private
  2795. * Template method that is to get and return the value of the filter.
  2796. * @return {String} The value of this filter
  2797. */
  2798. getValue : function () {
  2799. return this.menu.getValue();
  2800. },
  2801. /**
  2802. * @private
  2803. * Template method that is to set the value of the filter.
  2804. * @param {Object} value The value to set the filter
  2805. */
  2806. setValue : function (value) {
  2807. this.menu.setValue(value);
  2808. },
  2809. /**
  2810. * @private
  2811. * Template method that is to return <tt>true</tt> if the filter
  2812. * has enough configuration information to be activated.
  2813. * @return {Boolean}
  2814. */
  2815. isActivatable : function () {
  2816. var values = this.getValue();
  2817. for (key in values) {
  2818. if (values[key] !== undefined) {
  2819. return true;
  2820. }
  2821. }
  2822. return false;
  2823. },
  2824. /**
  2825. * @private
  2826. * Template method that is to get and return serialized filter data for
  2827. * transmission to the server.
  2828. * @return {Object/Array} An object or collection of objects containing
  2829. * key value pairs representing the current configuration of the filter.
  2830. */
  2831. getSerialArgs : function () {
  2832. var key,
  2833. args = [],
  2834. values = this.menu.getValue();
  2835. for (key in values) {
  2836. args.push({
  2837. type: 'numeric',
  2838. comparison: key,
  2839. value: values[key]
  2840. });
  2841. }
  2842. return args;
  2843. },
  2844. /**
  2845. * Template method that is to validate the provided Ext.data.Record
  2846. * against the filters configuration.
  2847. * @param {Ext.data.Record} record The record to validate
  2848. * @return {Boolean} true if the record is valid within the bounds
  2849. * of the filter, false otherwise.
  2850. */
  2851. validateRecord : function (record) {
  2852. var val = record.get(this.dataIndex),
  2853. values = this.getValue();
  2854. if (values.eq !== undefined && val != values.eq) {
  2855. return false;
  2856. }
  2857. if (values.lt !== undefined && val >= values.lt) {
  2858. return false;
  2859. }
  2860. if (values.gt !== undefined && val <= values.gt) {
  2861. return false;
  2862. }
  2863. return true;
  2864. }
  2865. });/**
  2866. * @class Ext.ux.grid.filter.StringFilter
  2867. * @extends Ext.ux.grid.filter.Filter
  2868. * Filter by a configurable Ext.form.TextField
  2869. * <p><b><u>Example Usage:</u></b></p>
  2870. * <pre><code>
  2871. var filters = new Ext.ux.grid.GridFilters({
  2872. ...
  2873. filters: [{
  2874. // required configs
  2875. type: 'string',
  2876. dataIndex: 'name',
  2877. // optional configs
  2878. value: 'foo',
  2879. active: true, // default is false
  2880. iconCls: 'ux-gridfilter-text-icon' // default
  2881. // any Ext.form.TextField configs accepted
  2882. }]
  2883. });
  2884. * </code></pre>
  2885. */
  2886. Ext.ux.grid.filter.StringFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
  2887. /**
  2888. * @cfg {String} iconCls
  2889. * The iconCls to be applied to the menu item.
  2890. * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.
  2891. */
  2892. iconCls : 'ux-gridfilter-text-icon',
  2893. emptyText: 'Enter Filter Text...',
  2894. selectOnFocus: true,
  2895. width: 125,
  2896. /**
  2897. * @private
  2898. * Template method that is to initialize the filter and install required menu items.
  2899. */
  2900. init : function (config) {
  2901. Ext.applyIf(config, {
  2902. enableKeyEvents: true,
  2903. iconCls: this.iconCls,
  2904. listeners: {
  2905. scope: this,
  2906. keyup: this.onInputKeyUp
  2907. }
  2908. });
  2909. this.inputItem = new Ext.form.TextField(config);
  2910. this.menu.add(this.inputItem);
  2911. this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
  2912. },
  2913. /**
  2914. * @private
  2915. * Template method that is to get and return the value of the filter.
  2916. * @return {String} The value of this filter
  2917. */
  2918. getValue : function () {
  2919. return this.inputItem.getValue();
  2920. },
  2921. /**
  2922. * @private
  2923. * Template method that is to set the value of the filter.
  2924. * @param {Object} value The value to set the filter
  2925. */
  2926. setValue : function (value) {
  2927. this.inputItem.setValue(value);
  2928. this.fireEvent('update', this);
  2929. },
  2930. /**
  2931. * @private
  2932. * Template method that is to return <tt>true</tt> if the filter
  2933. * has enough configuration information to be activated.
  2934. * @return {Boolean}
  2935. */
  2936. isActivatable : function () {
  2937. return this.inputItem.getValue().length > 0;
  2938. },
  2939. /**
  2940. * @private
  2941. * Template method that is to get and return serialized filter data for
  2942. * transmission to the server.
  2943. * @return {Object/Array} An object or collection of objects containing
  2944. * key value pairs representing the current configuration of the filter.
  2945. */
  2946. getSerialArgs : function () {
  2947. return {type: 'string', value: this.getValue()};
  2948. },
  2949. /**
  2950. * Template method that is to validate the provided Ext.data.Record
  2951. * against the filters configuration.
  2952. * @param {Ext.data.Record} record The record to validate
  2953. * @return {Boolean} true if the record is valid within the bounds
  2954. * of the filter, false otherwise.
  2955. */
  2956. validateRecord : function (record) {
  2957. var val = record.get(this.dataIndex);
  2958. if(typeof val != 'string') {
  2959. return (this.getValue().length === 0);
  2960. }
  2961. return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;
  2962. },
  2963. /**
  2964. * @private
  2965. * Handler method called when there is a keyup event on this.inputItem
  2966. */
  2967. onInputKeyUp : function (field, e) {
  2968. var k = e.getKey();
  2969. if (k == e.RETURN && field.isValid()) {
  2970. e.stopEvent();
  2971. this.menu.hide(true);
  2972. return;
  2973. }
  2974. // restart the timer
  2975. this.updateTask.delay(this.updateBuffer);
  2976. }
  2977. });
  2978. Ext.namespace('Ext.ux.menu');
  2979. /**
  2980. * @class Ext.ux.menu.ListMenu
  2981. * @extends Ext.menu.Menu
  2982. * This is a supporting class for {@link Ext.ux.grid.filter.ListFilter}.
  2983. * Although not listed as configuration options for this class, this class
  2984. * also accepts all configuration options from {@link Ext.ux.grid.filter.ListFilter}.
  2985. */
  2986. Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
  2987. /**
  2988. * @cfg {String} labelField
  2989. * Defaults to 'text'.
  2990. */
  2991. labelField : 'text',
  2992. /**
  2993. * @cfg {String} paramPrefix
  2994. * Defaults to 'Loading...'.
  2995. */
  2996. loadingText : 'Loading...',
  2997. /**
  2998. * @cfg {Boolean} loadOnShow
  2999. * Defaults to true.
  3000. */
  3001. loadOnShow : true,
  3002. /**
  3003. * @cfg {Boolean} single
  3004. * Specify true to group all items in this list into a single-select
  3005. * radio button group. Defaults to false.
  3006. */
  3007. single : false,
  3008. constructor : function (cfg) {
  3009. this.selected = [];
  3010. this.addEvents(
  3011. /**
  3012. * @event checkchange
  3013. * Fires when there is a change in checked items from this list
  3014. * @param {Object} item Ext.menu.CheckItem
  3015. * @param {Object} checked The checked value that was set
  3016. */
  3017. 'checkchange'
  3018. );
  3019. Ext.ux.menu.ListMenu.superclass.constructor.call(this, cfg = cfg || {});
  3020. if(!cfg.store && cfg.options){
  3021. var options = [];
  3022. for(var i=0, len=cfg.options.length; i<len; i++){
  3023. var value = cfg.options[i];
  3024. switch(Ext.type(value)){
  3025. case 'array': options.push(value); break;
  3026. case 'object': options.push([value.id, value[this.labelField]]); break;
  3027. case 'string': options.push([value, value]); break;
  3028. }
  3029. }
  3030. this.store = new Ext.data.Store({
  3031. reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField]),
  3032. data: options,
  3033. listeners: {
  3034. 'load': this.onLoad,
  3035. scope: this
  3036. }
  3037. });
  3038. this.loaded = true;
  3039. } else {
  3040. this.add({text: this.loadingText, iconCls: 'loading-indicator'});
  3041. this.store.on('load', this.onLoad, this);
  3042. }
  3043. },
  3044. destroy : function () {
  3045. if (this.store) {
  3046. this.store.destroy();
  3047. }
  3048. Ext.ux.menu.ListMenu.superclass.destroy.call(this);
  3049. },
  3050. /**
  3051. * Lists will initially show a 'loading' item while the data is retrieved from the store.
  3052. * In some cases the loaded data will result in a list that goes off the screen to the
  3053. * right (as placement calculations were done with the loading item). This adapter will
  3054. * allow show to be called with no arguments to show with the previous arguments and
  3055. * thus recalculate the width and potentially hang the menu from the left.
  3056. */
  3057. show : function () {
  3058. var lastArgs = null;
  3059. return function(){
  3060. if(arguments.length === 0){
  3061. Ext.ux.menu.ListMenu.superclass.show.apply(this, lastArgs);
  3062. } else {
  3063. lastArgs = arguments;
  3064. if (this.loadOnShow && !this.loaded) {
  3065. this.store.load();
  3066. }
  3067. Ext.ux.menu.ListMenu.superclass.show.apply(this, arguments);
  3068. }
  3069. };
  3070. }(),
  3071. /** @private */
  3072. onLoad : function (store, records) {
  3073. var visible = this.isVisible();
  3074. this.hide(false);
  3075. this.removeAll(true);
  3076. var gid = this.single ? Ext.id() : null;
  3077. for(var i=0, len=records.length; i<len; i++){
  3078. var item = new Ext.menu.CheckItem({
  3079. text: records[i].get(this.labelField),
  3080. group: gid,
  3081. checked: this.selected.indexOf(records[i].id) > -1,
  3082. hideOnClick: false});
  3083. item.itemId = records[i].id;
  3084. item.on('checkchange', this.checkChange, this);
  3085. this.add(item);
  3086. }
  3087. this.loaded = true;
  3088. if (visible) {
  3089. this.show();
  3090. }
  3091. this.fireEvent('load', this, records);
  3092. },
  3093. /**
  3094. * Get the selected items.
  3095. * @return {Array} selected
  3096. */
  3097. getSelected : function () {
  3098. return this.selected;
  3099. },
  3100. /** @private */
  3101. setSelected : function (value) {
  3102. value = this.selected = [].concat(value);
  3103. if (this.loaded) {
  3104. this.items.each(function(item){
  3105. item.setChecked(false, true);
  3106. for (var i = 0, len = value.length; i < len; i++) {
  3107. if (item.itemId == value[i]) {
  3108. item.setChecked(true, true);
  3109. }
  3110. }
  3111. }, this);
  3112. }
  3113. },
  3114. /**
  3115. * Handler for the 'checkchange' event from an check item in this menu
  3116. * @param {Object} item Ext.menu.CheckItem
  3117. * @param {Object} checked The checked value that was set
  3118. */
  3119. checkChange : function (item, checked) {
  3120. var value = [];
  3121. this.items.each(function(item){
  3122. if (item.checked) {
  3123. value.push(item.itemId);
  3124. }
  3125. },this);
  3126. this.selected = value;
  3127. this.fireEvent('checkchange', item, checked);
  3128. }
  3129. });Ext.ns('Ext.ux.menu');
  3130. /**
  3131. * @class Ext.ux.menu.RangeMenu
  3132. * @extends Ext.menu.Menu
  3133. * Custom implementation of Ext.menu.Menu that has preconfigured
  3134. * items for gt, lt, eq.
  3135. * <p><b><u>Example Usage:</u></b></p>
  3136. * <pre><code>
  3137. * </code></pre>
  3138. */
  3139. Ext.ux.menu.RangeMenu = Ext.extend(Ext.menu.Menu, {
  3140. constructor : function (config) {
  3141. Ext.ux.menu.RangeMenu.superclass.constructor.call(this, config);
  3142. this.addEvents(
  3143. /**
  3144. * @event update
  3145. * Fires when a filter configuration has changed
  3146. * @param {Ext.ux.grid.filter.Filter} this The filter object.
  3147. */
  3148. 'update'
  3149. );
  3150. this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
  3151. var i, len, item, cfg, Cls;
  3152. for (i = 0, len = this.menuItems.length; i < len; i++) {
  3153. item = this.menuItems[i];
  3154. if (item !== '-') {
  3155. // defaults
  3156. cfg = {
  3157. itemId: 'range-' + item,
  3158. enableKeyEvents: true,
  3159. iconCls: this.iconCls[item] || 'no-icon',
  3160. listeners: {
  3161. scope: this,
  3162. keyup: this.onInputKeyUp
  3163. }
  3164. };
  3165. Ext.apply(
  3166. cfg,
  3167. // custom configs
  3168. Ext.applyIf(this.fields[item] || {}, this.fieldCfg[item]),
  3169. // configurable defaults
  3170. this.menuItemCfgs
  3171. );
  3172. Cls = cfg.fieldCls || this.fieldCls;
  3173. item = this.fields[item] = new Cls(cfg);
  3174. }
  3175. this.add(item);
  3176. }
  3177. },
  3178. /**
  3179. * @private
  3180. * called by this.updateTask
  3181. */
  3182. fireUpdate : function () {
  3183. this.fireEvent('update', this);
  3184. },
  3185. /**
  3186. * Get and return the value of the filter.
  3187. * @return {String} The value of this filter
  3188. */
  3189. getValue : function () {
  3190. var result = {}, key, field;
  3191. for (key in this.fields) {
  3192. field = this.fields[key];
  3193. if (field.isValid() && String(field.getValue()).length > 0) {
  3194. result[key] = field.getValue();
  3195. }
  3196. }
  3197. return result;
  3198. },
  3199. /**
  3200. * Set the value of this menu and fires the 'update' event.
  3201. * @param {Object} data The data to assign to this menu
  3202. */
  3203. setValue : function (data) {
  3204. var key;
  3205. for (key in this.fields) {
  3206. this.fields[key].setValue(data[key] !== undefined ? data[key] : '');
  3207. }
  3208. this.fireEvent('update', this);
  3209. },
  3210. /**
  3211. * @private
  3212. * Handler method called when there is a keyup event on an input
  3213. * item of this menu.
  3214. */
  3215. onInputKeyUp : function (field, e) {
  3216. var k = e.getKey();
  3217. if (k == e.RETURN && field.isValid()) {
  3218. e.stopEvent();
  3219. this.hide(true);
  3220. return;
  3221. }
  3222. if (field == this.fields.eq) {
  3223. if (this.fields.gt) {
  3224. this.fields.gt.setValue(null);
  3225. }
  3226. if (this.fields.lt) {
  3227. this.fields.lt.setValue(null);
  3228. }
  3229. }
  3230. else {
  3231. this.fields.eq.setValue(null);
  3232. }
  3233. // restart the timer
  3234. this.updateTask.delay(this.updateBuffer);
  3235. }
  3236. });
  3237. Ext.ns('Ext.ux.grid');
  3238. /**
  3239. * @class Ext.ux.grid.GroupSummary
  3240. * @extends Ext.util.Observable
  3241. * A GridPanel plugin that enables dynamic column calculations and a dynamically
  3242. * updated grouped summary row.
  3243. */
  3244. Ext.ux.grid.GroupSummary = Ext.extend(Ext.util.Observable, {
  3245. /**
  3246. * @cfg {Function} summaryRenderer Renderer example:<pre><code>
  3247. summaryRenderer: function(v, params, data){
  3248. return ((v === 0 || v > 1) ? '(' + v +' Tasks)' : '(1 Task)');
  3249. },
  3250. * </code></pre>
  3251. */
  3252. /**
  3253. * @cfg {String} summaryType (Optional) The type of
  3254. * calculation to be used for the column. For options available see
  3255. * {@link #Calculations}.
  3256. */
  3257. constructor : function(config){
  3258. Ext.apply(this, config);
  3259. Ext.ux.grid.GroupSummary.superclass.constructor.call(this);
  3260. },
  3261. init : function(grid){
  3262. this.grid = grid;
  3263. var v = this.view = grid.getView();
  3264. v.doGroupEnd = this.doGroupEnd.createDelegate(this);
  3265. v.afterMethod('onColumnWidthUpdated', this.doWidth, this);
  3266. v.afterMethod('onAllColumnWidthsUpdated', this.doAllWidths, this);
  3267. v.afterMethod('onColumnHiddenUpdated', this.doHidden, this);
  3268. v.afterMethod('onUpdate', this.doUpdate, this);
  3269. v.afterMethod('onRemove', this.doRemove, this);
  3270. if(!this.rowTpl){
  3271. this.rowTpl = new Ext.Template(
  3272. '<div class="x-grid3-summary-row" style="{tstyle}">',
  3273. '<table class="x-grid3-summary-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
  3274. '<tbody><tr>{cells}</tr></tbody>',
  3275. '</table></div>'
  3276. );
  3277. this.rowTpl.disableFormats = true;
  3278. }
  3279. this.rowTpl.compile();
  3280. if(!this.cellTpl){
  3281. this.cellTpl = new Ext.Template(
  3282. '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
  3283. '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on">{value}</div>',
  3284. "</td>"
  3285. );
  3286. this.cellTpl.disableFormats = true;
  3287. }
  3288. this.cellTpl.compile();
  3289. },
  3290. /**
  3291. * Toggle the display of the summary row on/off
  3292. * @param {Boolean} visible <tt>true</tt> to show the summary, <tt>false</tt> to hide the summary.
  3293. */
  3294. toggleSummaries : function(visible){
  3295. var el = this.grid.getGridEl();
  3296. if(el){
  3297. if(visible === undefined){
  3298. visible = el.hasClass('x-grid-hide-summary');
  3299. }
  3300. el[visible ? 'removeClass' : 'addClass']('x-grid-hide-summary');
  3301. }
  3302. },
  3303. renderSummary : function(o, cs){
  3304. cs = cs || this.view.getColumnData();
  3305. var cfg = this.grid.getColumnModel().config,
  3306. buf = [], c, p = {}, cf, last = cs.length-1;
  3307. for(var i = 0, len = cs.length; i < len; i++){
  3308. c = cs[i];
  3309. cf = cfg[i];
  3310. p.id = c.id;
  3311. p.style = c.style;
  3312. p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
  3313. if(cf.summaryType || cf.summaryRenderer){
  3314. p.value = (cf.summaryRenderer || c.renderer)(o.data[c.name], p, o);
  3315. }else{
  3316. p.value = '';
  3317. }
  3318. if(p.value == undefined || p.value === "") p.value = "&#160;";
  3319. buf[buf.length] = this.cellTpl.apply(p);
  3320. }
  3321. return this.rowTpl.apply({
  3322. tstyle: 'width:'+this.view.getTotalWidth()+';',
  3323. cells: buf.join('')
  3324. });
  3325. },
  3326. /**
  3327. * @private
  3328. * @param {Object} rs
  3329. * @param {Object} cs
  3330. */
  3331. calculate : function(rs, cs){
  3332. var data = {}, r, c, cfg = this.grid.getColumnModel().config, cf;
  3333. for(var j = 0, jlen = rs.length; j < jlen; j++){
  3334. r = rs[j];
  3335. for(var i = 0, len = cs.length; i < len; i++){
  3336. c = cs[i];
  3337. cf = cfg[i];
  3338. if(cf.summaryType){
  3339. data[c.name] = Ext.ux.grid.GroupSummary.Calculations[cf.summaryType](data[c.name] || 0, r, c.name, data);
  3340. }
  3341. }
  3342. }
  3343. return data;
  3344. },
  3345. doGroupEnd : function(buf, g, cs, ds, colCount){
  3346. var data = this.calculate(g.rs, cs);
  3347. buf.push('</div>', this.renderSummary({data: data}, cs), '</div>');
  3348. },
  3349. doWidth : function(col, w, tw){
  3350. if(!this.isGrouped()){
  3351. return;
  3352. }
  3353. var gs = this.view.getGroups(),
  3354. len = gs.length,
  3355. i = 0,
  3356. s;
  3357. for(; i < len; ++i){
  3358. s = gs[i].childNodes[2];
  3359. s.style.width = tw;
  3360. s.firstChild.style.width = tw;
  3361. s.firstChild.rows[0].childNodes[col].style.width = w;
  3362. }
  3363. },
  3364. doAllWidths : function(ws, tw){
  3365. if(!this.isGrouped()){
  3366. return;
  3367. }
  3368. var gs = this.view.getGroups(),
  3369. len = gs.length,
  3370. i = 0,
  3371. j,
  3372. s,
  3373. cells,
  3374. wlen = ws.length;
  3375. for(; i < len; i++){
  3376. s = gs[i].childNodes[2];
  3377. s.style.width = tw;
  3378. s.firstChild.style.width = tw;
  3379. cells = s.firstChild.rows[0].childNodes;
  3380. for(j = 0; j < wlen; j++){
  3381. cells[j].style.width = ws[j];
  3382. }
  3383. }
  3384. },
  3385. doHidden : function(col, hidden, tw){
  3386. if(!this.isGrouped()){
  3387. return;
  3388. }
  3389. var gs = this.view.getGroups(),
  3390. len = gs.length,
  3391. i = 0,
  3392. s,
  3393. display = hidden ? 'none' : '';
  3394. for(; i < len; i++){
  3395. s = gs[i].childNodes[2];
  3396. s.style.width = tw;
  3397. s.firstChild.style.width = tw;
  3398. s.firstChild.rows[0].childNodes[col].style.display = display;
  3399. }
  3400. },
  3401. isGrouped : function(){
  3402. return !Ext.isEmpty(this.grid.getStore().groupField);
  3403. },
  3404. // Note: requires that all (or the first) record in the
  3405. // group share the same group value. Returns false if the group
  3406. // could not be found.
  3407. refreshSummary : function(groupValue){
  3408. return this.refreshSummaryById(this.view.getGroupId(groupValue));
  3409. },
  3410. getSummaryNode : function(gid){
  3411. var g = Ext.fly(gid, '_gsummary');
  3412. if(g){
  3413. return g.down('.x-grid3-summary-row', true);
  3414. }
  3415. return null;
  3416. },
  3417. refreshSummaryById : function(gid){
  3418. var g = Ext.getDom(gid);
  3419. if(!g){
  3420. return false;
  3421. }
  3422. var rs = [];
  3423. this.grid.getStore().each(function(r){
  3424. if(r._groupId == gid){
  3425. rs[rs.length] = r;
  3426. }
  3427. });
  3428. var cs = this.view.getColumnData(),
  3429. data = this.calculate(rs, cs),
  3430. markup = this.renderSummary({data: data}, cs),
  3431. existing = this.getSummaryNode(gid);
  3432. if(existing){
  3433. g.removeChild(existing);
  3434. }
  3435. Ext.DomHelper.append(g, markup);
  3436. return true;
  3437. },
  3438. doUpdate : function(ds, record){
  3439. this.refreshSummaryById(record._groupId);
  3440. },
  3441. doRemove : function(ds, record, index, isUpdate){
  3442. if(!isUpdate){
  3443. this.refreshSummaryById(record._groupId);
  3444. }
  3445. },
  3446. /**
  3447. * Show a message in the summary row.
  3448. * <pre><code>
  3449. grid.on('afteredit', function(){
  3450. var groupValue = 'Ext Forms: Field Anchoring';
  3451. summary.showSummaryMsg(groupValue, 'Updating Summary...');
  3452. });
  3453. * </code></pre>
  3454. * @param {String} groupValue
  3455. * @param {String} msg Text to use as innerHTML for the summary row.
  3456. */
  3457. showSummaryMsg : function(groupValue, msg){
  3458. var gid = this.view.getGroupId(groupValue),
  3459. node = this.getSummaryNode(gid);
  3460. if(node){
  3461. node.innerHTML = '<div class="x-grid3-summary-msg">' + msg + '</div>';
  3462. }
  3463. }
  3464. });
  3465. //backwards compat
  3466. Ext.grid.GroupSummary = Ext.ux.grid.GroupSummary;
  3467. /**
  3468. * Calculation types for summary row:</p><div class="mdetail-params"><ul>
  3469. * <li><b><tt>sum</tt></b> : <div class="sub-desc"></div></li>
  3470. * <li><b><tt>count</tt></b> : <div class="sub-desc"></div></li>
  3471. * <li><b><tt>max</tt></b> : <div class="sub-desc"></div></li>
  3472. * <li><b><tt>min</tt></b> : <div class="sub-desc"></div></li>
  3473. * <li><b><tt>average</tt></b> : <div class="sub-desc"></div></li>
  3474. * </ul></div>
  3475. * <p>Custom calculations may be implemented. An example of
  3476. * custom <code>summaryType=totalCost</code>:</p><pre><code>
  3477. // define a custom summary function
  3478. Ext.ux.grid.GroupSummary.Calculations['totalCost'] = function(v, record, field){
  3479. return v + (record.data.estimate * record.data.rate);
  3480. };
  3481. * </code></pre>
  3482. * @property Calculations
  3483. */
  3484. Ext.ux.grid.GroupSummary.Calculations = {
  3485. 'sum' : function(v, record, field){
  3486. return v + (record.data[field]||0);
  3487. },
  3488. 'count' : function(v, record, field, data){
  3489. return data[field+'count'] ? ++data[field+'count'] : (data[field+'count'] = 1);
  3490. },
  3491. 'max' : function(v, record, field, data){
  3492. var v = record.data[field];
  3493. var max = data[field+'max'] === undefined ? (data[field+'max'] = v) : data[field+'max'];
  3494. return v > max ? (data[field+'max'] = v) : max;
  3495. },
  3496. 'min' : function(v, record, field, data){
  3497. var v = record.data[field];
  3498. var min = data[field+'min'] === undefined ? (data[field+'min'] = v) : data[field+'min'];
  3499. return v < min ? (data[field+'min'] = v) : min;
  3500. },
  3501. 'average' : function(v, record, field, data){
  3502. var c = data[field+'count'] ? ++data[field+'count'] : (data[field+'count'] = 1);
  3503. var t = (data[field+'total'] = ((data[field+'total']||0) + (record.data[field]||0)));
  3504. return t === 0 ? 0 : t / c;
  3505. }
  3506. };
  3507. Ext.grid.GroupSummary.Calculations = Ext.ux.grid.GroupSummary.Calculations;
  3508. /**
  3509. * @class Ext.ux.grid.HybridSummary
  3510. * @extends Ext.ux.grid.GroupSummary
  3511. * Adds capability to specify the summary data for the group via json as illustrated here:
  3512. * <pre><code>
  3513. {
  3514. data: [
  3515. {
  3516. projectId: 100, project: 'House',
  3517. taskId: 112, description: 'Paint',
  3518. estimate: 6, rate: 150,
  3519. due:'06/24/2007'
  3520. },
  3521. ...
  3522. ],
  3523. summaryData: {
  3524. 'House': {
  3525. description: 14, estimate: 9,
  3526. rate: 99, due: new Date(2009, 6, 29),
  3527. cost: 999
  3528. }
  3529. }
  3530. }
  3531. * </code></pre>
  3532. *
  3533. */
  3534. Ext.ux.grid.HybridSummary = Ext.extend(Ext.ux.grid.GroupSummary, {
  3535. /**
  3536. * @private
  3537. * @param {Object} rs
  3538. * @param {Object} cs
  3539. */
  3540. calculate : function(rs, cs){
  3541. var gcol = this.view.getGroupField(),
  3542. gvalue = rs[0].data[gcol],
  3543. gdata = this.getSummaryData(gvalue);
  3544. return gdata || Ext.ux.grid.HybridSummary.superclass.calculate.call(this, rs, cs);
  3545. },
  3546. /**
  3547. * <pre><code>
  3548. grid.on('afteredit', function(){
  3549. var groupValue = 'Ext Forms: Field Anchoring';
  3550. summary.showSummaryMsg(groupValue, 'Updating Summary...');
  3551. setTimeout(function(){ // simulate server call
  3552. // HybridSummary class implements updateSummaryData
  3553. summary.updateSummaryData(groupValue,
  3554. // create data object based on configured dataIndex
  3555. {description: 22, estimate: 888, rate: 888, due: new Date(), cost: 8});
  3556. }, 2000);
  3557. });
  3558. * </code></pre>
  3559. * @param {String} groupValue
  3560. * @param {Object} data data object
  3561. * @param {Boolean} skipRefresh (Optional) Defaults to false
  3562. */
  3563. updateSummaryData : function(groupValue, data, skipRefresh){
  3564. var json = this.grid.getStore().reader.jsonData;
  3565. if(!json.summaryData){
  3566. json.summaryData = {};
  3567. }
  3568. json.summaryData[groupValue] = data;
  3569. if(!skipRefresh){
  3570. this.refreshSummary(groupValue);
  3571. }
  3572. },
  3573. /**
  3574. * Returns the summaryData for the specified groupValue or null.
  3575. * @param {String} groupValue
  3576. * @return {Object} summaryData
  3577. */
  3578. getSummaryData : function(groupValue){
  3579. var reader = this.grid.getStore().reader,
  3580. json = reader.jsonData,
  3581. fields = reader.recordType.prototype.fields,
  3582. v;
  3583. if(json && json.summaryData){
  3584. v = json.summaryData[groupValue];
  3585. if(v){
  3586. return reader.extractValues(v, fields.items, fields.length);
  3587. }
  3588. }
  3589. return null;
  3590. }
  3591. });
  3592. //backwards compat
  3593. Ext.grid.HybridSummary = Ext.ux.grid.HybridSummary;
  3594. Ext.ux.GroupTab = Ext.extend(Ext.Container, {
  3595. mainItem: 0,
  3596. expanded: true,
  3597. deferredRender: true,
  3598. activeTab: null,
  3599. idDelimiter: '__',
  3600. headerAsText: false,
  3601. frame: false,
  3602. hideBorders: true,
  3603. initComponent: function(config){
  3604. Ext.apply(this, config);
  3605. this.frame = false;
  3606. Ext.ux.GroupTab.superclass.initComponent.call(this);
  3607. this.addEvents('activate', 'deactivate', 'changemainitem', 'beforetabchange', 'tabchange');
  3608. this.setLayout(new Ext.layout.CardLayout({
  3609. deferredRender: this.deferredRender
  3610. }));
  3611. if (!this.stack) {
  3612. this.stack = Ext.TabPanel.AccessStack();
  3613. }
  3614. this.initItems();
  3615. this.on('beforerender', function(){
  3616. this.groupEl = this.ownerCt.getGroupEl(this);
  3617. }, this);
  3618. this.on('add', this.onAdd, this, {
  3619. target: this
  3620. });
  3621. this.on('remove', this.onRemove, this, {
  3622. target: this
  3623. });
  3624. if (this.mainItem !== undefined) {
  3625. var item = (typeof this.mainItem == 'object') ? this.mainItem : this.items.get(this.mainItem);
  3626. delete this.mainItem;
  3627. this.setMainItem(item);
  3628. }
  3629. },
  3630. /**
  3631. * Sets the specified tab as the active tab. This method fires the {@link #beforetabchange} event which
  3632. * can return false to cancel the tab change.
  3633. * @param {String/Panel} tab The id or tab Panel to activate
  3634. */
  3635. setActiveTab : function(item){
  3636. item = this.getComponent(item);
  3637. if(!item){
  3638. return false;
  3639. }
  3640. if(!this.rendered){
  3641. this.activeTab = item;
  3642. return true;
  3643. }
  3644. if(this.activeTab != item && this.fireEvent('beforetabchange', this, item, this.activeTab) !== false){
  3645. if(this.activeTab && this.activeTab != this.mainItem){
  3646. var oldEl = this.getTabEl(this.activeTab);
  3647. if(oldEl){
  3648. Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
  3649. }
  3650. }
  3651. var el = this.getTabEl(item);
  3652. Ext.fly(el).addClass('x-grouptabs-strip-active');
  3653. this.activeTab = item;
  3654. this.stack.add(item);
  3655. this.layout.setActiveItem(item);
  3656. if(this.layoutOnTabChange && item.doLayout){
  3657. item.doLayout();
  3658. }
  3659. if(this.scrolling){
  3660. this.scrollToTab(item, this.animScroll);
  3661. }
  3662. this.fireEvent('tabchange', this, item);
  3663. return true;
  3664. }
  3665. return false;
  3666. },
  3667. getTabEl: function(item){
  3668. if (item == this.mainItem) {
  3669. return this.groupEl;
  3670. }
  3671. return Ext.TabPanel.prototype.getTabEl.call(this, item);
  3672. },
  3673. onRender: function(ct, position){
  3674. Ext.ux.GroupTab.superclass.onRender.call(this, ct, position);
  3675. this.strip = Ext.fly(this.groupEl).createChild({
  3676. tag: 'ul',
  3677. cls: 'x-grouptabs-sub'
  3678. });
  3679. this.tooltip = new Ext.ToolTip({
  3680. target: this.groupEl,
  3681. delegate: 'a.x-grouptabs-text',
  3682. trackMouse: true,
  3683. renderTo: document.body,
  3684. listeners: {
  3685. beforeshow: function(tip) {
  3686. var item = (tip.triggerElement.parentNode === this.mainItem.tabEl)
  3687. ? this.mainItem
  3688. : this.findById(tip.triggerElement.parentNode.id.split(this.idDelimiter)[1]);
  3689. if(!item.tabTip) {
  3690. return false;
  3691. }
  3692. tip.body.dom.innerHTML = item.tabTip;
  3693. },
  3694. scope: this
  3695. }
  3696. });
  3697. if (!this.itemTpl) {
  3698. var tt = new Ext.Template('<li class="{cls}" id="{id}">', '<a onclick="return false;" class="x-grouptabs-text {iconCls}">{text}</a>', '</li>');
  3699. tt.disableFormats = true;
  3700. tt.compile();
  3701. Ext.ux.GroupTab.prototype.itemTpl = tt;
  3702. }
  3703. this.items.each(this.initTab, this);
  3704. },
  3705. afterRender: function(){
  3706. Ext.ux.GroupTab.superclass.afterRender.call(this);
  3707. if (this.activeTab !== undefined) {
  3708. var item = (typeof this.activeTab == 'object') ? this.activeTab : this.items.get(this.activeTab);
  3709. delete this.activeTab;
  3710. this.setActiveTab(item);
  3711. }
  3712. },
  3713. // private
  3714. initTab: function(item, index){
  3715. var before = this.strip.dom.childNodes[index];
  3716. var p = Ext.TabPanel.prototype.getTemplateArgs.call(this, item);
  3717. if (item === this.mainItem) {
  3718. item.tabEl = this.groupEl;
  3719. p.cls += ' x-grouptabs-main-item';
  3720. }
  3721. var el = before ? this.itemTpl.insertBefore(before, p) : this.itemTpl.append(this.strip, p);
  3722. item.tabEl = item.tabEl || el;
  3723. item.on('disable', this.onItemDisabled, this);
  3724. item.on('enable', this.onItemEnabled, this);
  3725. item.on('titlechange', this.onItemTitleChanged, this);
  3726. item.on('iconchange', this.onItemIconChanged, this);
  3727. item.on('beforeshow', this.onBeforeShowItem, this);
  3728. },
  3729. setMainItem: function(item){
  3730. item = this.getComponent(item);
  3731. if (!item || this.fireEvent('changemainitem', this, item, this.mainItem) === false) {
  3732. return;
  3733. }
  3734. this.mainItem = item;
  3735. },
  3736. getMainItem: function(){
  3737. return this.mainItem || null;
  3738. },
  3739. // private
  3740. onBeforeShowItem: function(item){
  3741. if (item != this.activeTab) {
  3742. this.setActiveTab(item);
  3743. return false;
  3744. }
  3745. },
  3746. // private
  3747. onAdd: function(gt, item, index){
  3748. if (this.rendered) {
  3749. this.initTab.call(this, item, index);
  3750. }
  3751. },
  3752. // private
  3753. onRemove: function(tp, item){
  3754. Ext.destroy(Ext.get(this.getTabEl(item)));
  3755. this.stack.remove(item);
  3756. item.un('disable', this.onItemDisabled, this);
  3757. item.un('enable', this.onItemEnabled, this);
  3758. item.un('titlechange', this.onItemTitleChanged, this);
  3759. item.un('iconchange', this.onItemIconChanged, this);
  3760. item.un('beforeshow', this.onBeforeShowItem, this);
  3761. if (item == this.activeTab) {
  3762. var next = this.stack.next();
  3763. if (next) {
  3764. this.setActiveTab(next);
  3765. }
  3766. else if (this.items.getCount() > 0) {
  3767. this.setActiveTab(0);
  3768. }
  3769. else {
  3770. this.activeTab = null;
  3771. }
  3772. }
  3773. },
  3774. // private
  3775. onBeforeAdd: function(item){
  3776. var existing = item.events ? (this.items.containsKey(item.getItemId()) ? item : null) : this.items.get(item);
  3777. if (existing) {
  3778. this.setActiveTab(item);
  3779. return false;
  3780. }
  3781. Ext.TabPanel.superclass.onBeforeAdd.apply(this, arguments);
  3782. var es = item.elements;
  3783. item.elements = es ? es.replace(',header', '') : es;
  3784. item.border = (item.border === true);
  3785. },
  3786. // private
  3787. onItemDisabled: Ext.TabPanel.prototype.onItemDisabled,
  3788. onItemEnabled: Ext.TabPanel.prototype.onItemEnabled,
  3789. // private
  3790. onItemTitleChanged: function(item){
  3791. var el = this.getTabEl(item);
  3792. if (el) {
  3793. Ext.fly(el).child('a.x-grouptabs-text', true).innerHTML = item.title;
  3794. }
  3795. },
  3796. //private
  3797. onItemIconChanged: function(item, iconCls, oldCls){
  3798. var el = this.getTabEl(item);
  3799. if (el) {
  3800. Ext.fly(el).child('a.x-grouptabs-text').replaceClass(oldCls, iconCls);
  3801. }
  3802. },
  3803. beforeDestroy: function(){
  3804. Ext.TabPanel.prototype.beforeDestroy.call(this);
  3805. this.tooltip.destroy();
  3806. }
  3807. });
  3808. Ext.reg('grouptab', Ext.ux.GroupTab);
  3809. Ext.ns('Ext.ux');
  3810. Ext.ux.GroupTabPanel = Ext.extend(Ext.TabPanel, {
  3811. tabPosition: 'left',
  3812. alternateColor: false,
  3813. alternateCls: 'x-grouptabs-panel-alt',
  3814. defaultType: 'grouptab',
  3815. deferredRender: false,
  3816. activeGroup : null,
  3817. initComponent: function(){
  3818. Ext.ux.GroupTabPanel.superclass.initComponent.call(this);
  3819. this.addEvents(
  3820. 'beforegroupchange',
  3821. 'groupchange'
  3822. );
  3823. this.elements = 'body,header';
  3824. this.stripTarget = 'header';
  3825. this.tabPosition = this.tabPosition == 'right' ? 'right' : 'left';
  3826. this.addClass('x-grouptabs-panel');
  3827. if (this.tabStyle && this.tabStyle != '') {
  3828. this.addClass('x-grouptabs-panel-' + this.tabStyle);
  3829. }
  3830. if (this.alternateColor) {
  3831. this.addClass(this.alternateCls);
  3832. }
  3833. this.on('beforeadd', function(gtp, item, index){
  3834. this.initGroup(item, index);
  3835. });
  3836. this.items.each(function(item){
  3837. item.on('tabchange',function(item){
  3838. this.fireEvent('tabchange', this, item.activeTab);
  3839. }, this);
  3840. },this);
  3841. },
  3842. initEvents : function() {
  3843. this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);
  3844. },
  3845. onRender: function(ct, position){
  3846. Ext.TabPanel.superclass.onRender.call(this, ct, position);
  3847. if(this.plain){
  3848. var pos = this.tabPosition == 'top' ? 'header' : 'footer';
  3849. this[pos].addClass('x-tab-panel-'+pos+'-plain');
  3850. }
  3851. var st = this[this.stripTarget];
  3852. this.stripWrap = st.createChild({cls:'x-tab-strip-wrap ', cn:{
  3853. tag:'ul', cls:'x-grouptabs-strip x-grouptabs-tab-strip-'+this.tabPosition}});
  3854. var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
  3855. this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
  3856. this.header.addClass('x-grouptabs-panel-header');
  3857. this.bwrap.addClass('x-grouptabs-bwrap');
  3858. this.body.addClass('x-tab-panel-body-'+this.tabPosition + ' x-grouptabs-panel-body');
  3859. if (!this.groupTpl) {
  3860. var tt = new Ext.Template(
  3861. '<li class="{cls}" id="{id}">',
  3862. '<a class="x-grouptabs-expand" onclick="return false;"></a>',
  3863. '<a class="x-grouptabs-text {iconCls}" href="#" onclick="return false;">',
  3864. '<span>{text}</span></a>',
  3865. '</li>'
  3866. );
  3867. tt.disableFormats = true;
  3868. tt.compile();
  3869. Ext.ux.GroupTabPanel.prototype.groupTpl = tt;
  3870. }
  3871. this.items.each(this.initGroup, this);
  3872. },
  3873. afterRender: function(){
  3874. Ext.ux.GroupTabPanel.superclass.afterRender.call(this);
  3875. this.tabJoint = Ext.fly(this.body.dom.parentNode).createChild({
  3876. cls: 'x-tab-joint'
  3877. });
  3878. this.addClass('x-tab-panel-' + this.tabPosition);
  3879. this.header.setWidth(this.tabWidth);
  3880. if (this.activeGroup !== undefined) {
  3881. var group = (typeof this.activeGroup == 'object') ? this.activeGroup : this.items.get(this.activeGroup);
  3882. delete this.activeGroup;
  3883. this.setActiveGroup(group);
  3884. group.setActiveTab(group.getMainItem());
  3885. }
  3886. },
  3887. getGroupEl : Ext.TabPanel.prototype.getTabEl,
  3888. // private
  3889. findTargets: function(e){
  3890. var item = null,
  3891. itemEl = e.getTarget('li', this.strip);
  3892. if (itemEl) {
  3893. item = this.findById(itemEl.id.split(this.idDelimiter)[1]);
  3894. if (item.disabled) {
  3895. return {
  3896. expand: null,
  3897. item: null,
  3898. el: null
  3899. };
  3900. }
  3901. }
  3902. return {
  3903. expand: e.getTarget('.x-grouptabs-expand', this.strip),
  3904. isGroup: !e.getTarget('ul.x-grouptabs-sub', this.strip),
  3905. item: item,
  3906. el: itemEl
  3907. };
  3908. },
  3909. // private
  3910. onStripMouseDown: function(e){
  3911. if (e.button != 0) {
  3912. return;
  3913. }
  3914. e.preventDefault();
  3915. var t = this.findTargets(e);
  3916. if (t.expand) {
  3917. this.toggleGroup(t.el);
  3918. }
  3919. else if (t.item) {
  3920. if(t.isGroup) {
  3921. t.item.setActiveTab(t.item.getMainItem());
  3922. }
  3923. else {
  3924. t.item.ownerCt.setActiveTab(t.item);
  3925. }
  3926. }
  3927. },
  3928. expandGroup: function(groupEl){
  3929. if(groupEl.isXType) {
  3930. groupEl = this.getGroupEl(groupEl);
  3931. }
  3932. Ext.fly(groupEl).addClass('x-grouptabs-expanded');
  3933. this.syncTabJoint();
  3934. },
  3935. toggleGroup: function(groupEl){
  3936. if(groupEl.isXType) {
  3937. groupEl = this.getGroupEl(groupEl);
  3938. }
  3939. Ext.fly(groupEl).toggleClass('x-grouptabs-expanded');
  3940. this.syncTabJoint();
  3941. },
  3942. collapseGroup: function(groupEl){
  3943. if(groupEl.isXType) {
  3944. groupEl = this.getGroupEl(groupEl);
  3945. }
  3946. Ext.fly(groupEl).removeClass('x-grouptabs-expanded');
  3947. this.syncTabJoint();
  3948. },
  3949. syncTabJoint: function(groupEl){
  3950. if (!this.tabJoint) {
  3951. return;
  3952. }
  3953. groupEl = groupEl || this.getGroupEl(this.activeGroup);
  3954. if(groupEl) {
  3955. this.tabJoint.setHeight(Ext.fly(groupEl).getHeight() - 2);
  3956. var y = Ext.isGecko2 ? 0 : 1;
  3957. if (this.tabPosition == 'left'){
  3958. this.tabJoint.alignTo(groupEl, 'tl-tr', [-2,y]);
  3959. }
  3960. else {
  3961. this.tabJoint.alignTo(groupEl, 'tr-tl', [1,y]);
  3962. }
  3963. }
  3964. else {
  3965. this.tabJoint.hide();
  3966. }
  3967. },
  3968. getActiveTab : function() {
  3969. if(!this.activeGroup) return null;
  3970. return this.activeGroup.getTabEl(this.activeGroup.activeTab) || null;
  3971. },
  3972. onResize: function(){
  3973. Ext.ux.GroupTabPanel.superclass.onResize.apply(this, arguments);
  3974. this.syncTabJoint();
  3975. },
  3976. createCorner: function(el, pos){
  3977. return Ext.fly(el).createChild({
  3978. cls: 'x-grouptabs-corner x-grouptabs-corner-' + pos
  3979. });
  3980. },
  3981. initGroup: function(group, index){
  3982. var before = this.strip.dom.childNodes[index],
  3983. p = this.getTemplateArgs(group);
  3984. if (index === 0) {
  3985. p.cls += ' x-tab-first';
  3986. }
  3987. p.cls += ' x-grouptabs-main';
  3988. p.text = group.getMainItem().title;
  3989. var el = before ? this.groupTpl.insertBefore(before, p) : this.groupTpl.append(this.strip, p),
  3990. tl = this.createCorner(el, 'top-' + this.tabPosition),
  3991. bl = this.createCorner(el, 'bottom-' + this.tabPosition);
  3992. group.tabEl = el;
  3993. if (group.expanded) {
  3994. this.expandGroup(el);
  3995. }
  3996. if (Ext.isIE6 || (Ext.isIE && !Ext.isStrict)){
  3997. bl.setLeft('-10px');
  3998. bl.setBottom('-5px');
  3999. tl.setLeft('-10px');
  4000. tl.setTop('-5px');
  4001. }
  4002. this.mon(group, {
  4003. scope: this,
  4004. changemainitem: this.onGroupChangeMainItem,
  4005. beforetabchange: this.onGroupBeforeTabChange
  4006. });
  4007. },
  4008. setActiveGroup : function(group) {
  4009. group = this.getComponent(group);
  4010. if(!group){
  4011. return false;
  4012. }
  4013. if(!this.rendered){
  4014. this.activeGroup = group;
  4015. return true;
  4016. }
  4017. if(this.activeGroup != group && this.fireEvent('beforegroupchange', this, group, this.activeGroup) !== false){
  4018. if(this.activeGroup){
  4019. this.activeGroup.activeTab = null;
  4020. var oldEl = this.getGroupEl(this.activeGroup);
  4021. if(oldEl){
  4022. Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
  4023. }
  4024. }
  4025. var groupEl = this.getGroupEl(group);
  4026. Ext.fly(groupEl).addClass('x-grouptabs-strip-active');
  4027. this.activeGroup = group;
  4028. this.stack.add(group);
  4029. this.layout.setActiveItem(group);
  4030. this.syncTabJoint(groupEl);
  4031. this.fireEvent('groupchange', this, group);
  4032. return true;
  4033. }
  4034. return false;
  4035. },
  4036. onGroupBeforeTabChange: function(group, newTab, oldTab){
  4037. if(group !== this.activeGroup || newTab !== oldTab) {
  4038. this.strip.select('.x-grouptabs-sub > li.x-grouptabs-strip-active', true).removeClass('x-grouptabs-strip-active');
  4039. }
  4040. this.expandGroup(this.getGroupEl(group));
  4041. if(group !== this.activeGroup) {
  4042. return this.setActiveGroup(group);
  4043. }
  4044. },
  4045. getFrameHeight: function(){
  4046. var h = this.el.getFrameWidth('tb');
  4047. h += (this.tbar ? this.tbar.getHeight() : 0) +
  4048. (this.bbar ? this.bbar.getHeight() : 0);
  4049. return h;
  4050. },
  4051. adjustBodyWidth: function(w){
  4052. return w - this.tabWidth;
  4053. }
  4054. });
  4055. Ext.reg('grouptabpanel', Ext.ux.GroupTabPanel);
  4056. /*
  4057. * Note that this control will most likely remain as an example, and not as a core Ext form
  4058. * control. However, the API will be changing in a future release and so should not yet be
  4059. * treated as a final, stable API at this time.
  4060. */
  4061. /**
  4062. * @class Ext.ux.form.ItemSelector
  4063. * @extends Ext.form.Field
  4064. * A control that allows selection of between two Ext.ux.form.MultiSelect controls.
  4065. *
  4066. * @history
  4067. * 2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
  4068. *
  4069. * @constructor
  4070. * Create a new ItemSelector
  4071. * @param {Object} config Configuration options
  4072. * @xtype itemselector
  4073. */
  4074. Ext.ux.form.ItemSelector = Ext.extend(Ext.form.Field, {
  4075. hideNavIcons:false,
  4076. imagePath:"",
  4077. iconUp:"up2.gif",
  4078. iconDown:"down2.gif",
  4079. iconLeft:"left2.gif",
  4080. iconRight:"right2.gif",
  4081. iconTop:"top2.gif",
  4082. iconBottom:"bottom2.gif",
  4083. drawUpIcon:true,
  4084. drawDownIcon:true,
  4085. drawLeftIcon:true,
  4086. drawRightIcon:true,
  4087. drawTopIcon:true,
  4088. drawBotIcon:true,
  4089. delimiter:',',
  4090. bodyStyle:null,
  4091. border:false,
  4092. defaultAutoCreate:{tag: "div"},
  4093. /**
  4094. * @cfg {Array} multiselects An array of {@link Ext.ux.form.MultiSelect} config objects, with at least all required parameters (e.g., store)
  4095. */
  4096. multiselects:null,
  4097. initComponent: function(){
  4098. Ext.ux.form.ItemSelector.superclass.initComponent.call(this);
  4099. this.addEvents({
  4100. 'rowdblclick' : true,
  4101. 'change' : true
  4102. });
  4103. },
  4104. onRender: function(ct, position){
  4105. Ext.ux.form.ItemSelector.superclass.onRender.call(this, ct, position);
  4106. // Internal default configuration for both multiselects
  4107. var msConfig = [{
  4108. legend: 'Available',
  4109. draggable: true,
  4110. droppable: true,
  4111. width: 100,
  4112. height: 100
  4113. },{
  4114. legend: 'Selected',
  4115. droppable: true,
  4116. draggable: true,
  4117. width: 100,
  4118. height: 100
  4119. }];
  4120. this.fromMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[0], msConfig[0]));
  4121. this.fromMultiselect.on('dblclick', this.onRowDblClick, this);
  4122. this.toMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[1], msConfig[1]));
  4123. this.toMultiselect.on('dblclick', this.onRowDblClick, this);
  4124. var p = new Ext.Panel({
  4125. bodyStyle:this.bodyStyle,
  4126. border:this.border,
  4127. layout:"table",
  4128. layoutConfig:{columns:3}
  4129. });
  4130. p.add(this.fromMultiselect);
  4131. var icons = new Ext.Panel({header:false});
  4132. p.add(icons);
  4133. p.add(this.toMultiselect);
  4134. p.render(this.el);
  4135. icons.el.down('.'+icons.bwrapCls).remove();
  4136. // ICON HELL!!!
  4137. if (this.imagePath!="" && this.imagePath.charAt(this.imagePath.length-1)!="/")
  4138. this.imagePath+="/";
  4139. this.iconUp = this.imagePath + (this.iconUp || 'up2.gif');
  4140. this.iconDown = this.imagePath + (this.iconDown || 'down2.gif');
  4141. this.iconLeft = this.imagePath + (this.iconLeft || 'left2.gif');
  4142. this.iconRight = this.imagePath + (this.iconRight || 'right2.gif');
  4143. this.iconTop = this.imagePath + (this.iconTop || 'top2.gif');
  4144. this.iconBottom = this.imagePath + (this.iconBottom || 'bottom2.gif');
  4145. var el=icons.getEl();
  4146. this.toTopIcon = el.createChild({tag:'img', src:this.iconTop, style:{cursor:'pointer', margin:'2px'}});
  4147. el.createChild({tag: 'br'});
  4148. this.upIcon = el.createChild({tag:'img', src:this.iconUp, style:{cursor:'pointer', margin:'2px'}});
  4149. el.createChild({tag: 'br'});
  4150. this.addIcon = el.createChild({tag:'img', src:this.iconRight, style:{cursor:'pointer', margin:'2px'}});
  4151. el.createChild({tag: 'br'});
  4152. this.removeIcon = el.createChild({tag:'img', src:this.iconLeft, style:{cursor:'pointer', margin:'2px'}});
  4153. el.createChild({tag: 'br'});
  4154. this.downIcon = el.createChild({tag:'img', src:this.iconDown, style:{cursor:'pointer', margin:'2px'}});
  4155. el.createChild({tag: 'br'});
  4156. this.toBottomIcon = el.createChild({tag:'img', src:this.iconBottom, style:{cursor:'pointer', margin:'2px'}});
  4157. this.toTopIcon.on('click', this.toTop, this);
  4158. this.upIcon.on('click', this.up, this);
  4159. this.downIcon.on('click', this.down, this);
  4160. this.toBottomIcon.on('click', this.toBottom, this);
  4161. this.addIcon.on('click', this.fromTo, this);
  4162. this.removeIcon.on('click', this.toFrom, this);
  4163. if (!this.drawUpIcon || this.hideNavIcons) { this.upIcon.dom.style.display='none'; }
  4164. if (!this.drawDownIcon || this.hideNavIcons) { this.downIcon.dom.style.display='none'; }
  4165. if (!this.drawLeftIcon || this.hideNavIcons) { this.addIcon.dom.style.display='none'; }
  4166. if (!this.drawRightIcon || this.hideNavIcons) { this.removeIcon.dom.style.display='none'; }
  4167. if (!this.drawTopIcon || this.hideNavIcons) { this.toTopIcon.dom.style.display='none'; }
  4168. if (!this.drawBotIcon || this.hideNavIcons) { this.toBottomIcon.dom.style.display='none'; }
  4169. var tb = p.body.first();
  4170. this.el.setWidth(p.body.first().getWidth());
  4171. p.body.removeClass();
  4172. this.hiddenName = this.name;
  4173. var hiddenTag = {tag: "input", type: "hidden", value: "", name: this.name};
  4174. this.hiddenField = this.el.createChild(hiddenTag);
  4175. },
  4176. doLayout: function(){
  4177. if(this.rendered){
  4178. this.fromMultiselect.fs.doLayout();
  4179. this.toMultiselect.fs.doLayout();
  4180. }
  4181. },
  4182. afterRender: function(){
  4183. Ext.ux.form.ItemSelector.superclass.afterRender.call(this);
  4184. this.toStore = this.toMultiselect.store;
  4185. this.toStore.on('add', this.valueChanged, this);
  4186. this.toStore.on('remove', this.valueChanged, this);
  4187. this.toStore.on('load', this.valueChanged, this);
  4188. this.valueChanged(this.toStore);
  4189. },
  4190. toTop : function() {
  4191. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  4192. var records = [];
  4193. if (selectionsArray.length > 0) {
  4194. selectionsArray.sort();
  4195. for (var i=0; i<selectionsArray.length; i++) {
  4196. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  4197. records.push(record);
  4198. }
  4199. selectionsArray = [];
  4200. for (var i=records.length-1; i>-1; i--) {
  4201. record = records[i];
  4202. this.toMultiselect.view.store.remove(record);
  4203. this.toMultiselect.view.store.insert(0, record);
  4204. selectionsArray.push(((records.length - 1) - i));
  4205. }
  4206. }
  4207. this.toMultiselect.view.refresh();
  4208. this.toMultiselect.view.select(selectionsArray);
  4209. },
  4210. toBottom : function() {
  4211. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  4212. var records = [];
  4213. if (selectionsArray.length > 0) {
  4214. selectionsArray.sort();
  4215. for (var i=0; i<selectionsArray.length; i++) {
  4216. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  4217. records.push(record);
  4218. }
  4219. selectionsArray = [];
  4220. for (var i=0; i<records.length; i++) {
  4221. record = records[i];
  4222. this.toMultiselect.view.store.remove(record);
  4223. this.toMultiselect.view.store.add(record);
  4224. selectionsArray.push((this.toMultiselect.view.store.getCount()) - (records.length - i));
  4225. }
  4226. }
  4227. this.toMultiselect.view.refresh();
  4228. this.toMultiselect.view.select(selectionsArray);
  4229. },
  4230. up : function() {
  4231. var record = null;
  4232. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  4233. selectionsArray.sort();
  4234. var newSelectionsArray = [];
  4235. if (selectionsArray.length > 0) {
  4236. for (var i=0; i<selectionsArray.length; i++) {
  4237. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  4238. if ((selectionsArray[i] - 1) >= 0) {
  4239. this.toMultiselect.view.store.remove(record);
  4240. this.toMultiselect.view.store.insert(selectionsArray[i] - 1, record);
  4241. newSelectionsArray.push(selectionsArray[i] - 1);
  4242. }
  4243. }
  4244. this.toMultiselect.view.refresh();
  4245. this.toMultiselect.view.select(newSelectionsArray);
  4246. }
  4247. },
  4248. down : function() {
  4249. var record = null;
  4250. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  4251. selectionsArray.sort();
  4252. selectionsArray.reverse();
  4253. var newSelectionsArray = [];
  4254. if (selectionsArray.length > 0) {
  4255. for (var i=0; i<selectionsArray.length; i++) {
  4256. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  4257. if ((selectionsArray[i] + 1) < this.toMultiselect.view.store.getCount()) {
  4258. this.toMultiselect.view.store.remove(record);
  4259. this.toMultiselect.view.store.insert(selectionsArray[i] + 1, record);
  4260. newSelectionsArray.push(selectionsArray[i] + 1);
  4261. }
  4262. }
  4263. this.toMultiselect.view.refresh();
  4264. this.toMultiselect.view.select(newSelectionsArray);
  4265. }
  4266. },
  4267. fromTo : function() {
  4268. var selectionsArray = this.fromMultiselect.view.getSelectedIndexes();
  4269. var records = [];
  4270. if (selectionsArray.length > 0) {
  4271. for (var i=0; i<selectionsArray.length; i++) {
  4272. record = this.fromMultiselect.view.store.getAt(selectionsArray[i]);
  4273. records.push(record);
  4274. }
  4275. if(!this.allowDup)selectionsArray = [];
  4276. for (var i=0; i<records.length; i++) {
  4277. record = records[i];
  4278. if(this.allowDup){
  4279. var x=new Ext.data.Record();
  4280. record.id=x.id;
  4281. delete x;
  4282. this.toMultiselect.view.store.add(record);
  4283. }else{
  4284. this.fromMultiselect.view.store.remove(record);
  4285. this.toMultiselect.view.store.add(record);
  4286. selectionsArray.push((this.toMultiselect.view.store.getCount() - 1));
  4287. }
  4288. }
  4289. }
  4290. this.toMultiselect.view.refresh();
  4291. this.fromMultiselect.view.refresh();
  4292. var si = this.toMultiselect.store.sortInfo;
  4293. if(si){
  4294. this.toMultiselect.store.sort(si.field, si.direction);
  4295. }
  4296. this.toMultiselect.view.select(selectionsArray);
  4297. },
  4298. toFrom : function() {
  4299. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  4300. var records = [];
  4301. if (selectionsArray.length > 0) {
  4302. for (var i=0; i<selectionsArray.length; i++) {
  4303. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  4304. records.push(record);
  4305. }
  4306. selectionsArray = [];
  4307. for (var i=0; i<records.length; i++) {
  4308. record = records[i];
  4309. this.toMultiselect.view.store.remove(record);
  4310. if(!this.allowDup){
  4311. this.fromMultiselect.view.store.add(record);
  4312. selectionsArray.push((this.fromMultiselect.view.store.getCount() - 1));
  4313. }
  4314. }
  4315. }
  4316. this.fromMultiselect.view.refresh();
  4317. this.toMultiselect.view.refresh();
  4318. var si = this.fromMultiselect.store.sortInfo;
  4319. if (si){
  4320. this.fromMultiselect.store.sort(si.field, si.direction);
  4321. }
  4322. this.fromMultiselect.view.select(selectionsArray);
  4323. },
  4324. valueChanged: function(store) {
  4325. var record = null;
  4326. var values = [];
  4327. for (var i=0; i<store.getCount(); i++) {
  4328. record = store.getAt(i);
  4329. values.push(record.get(this.toMultiselect.valueField));
  4330. }
  4331. this.hiddenField.dom.value = values.join(this.delimiter);
  4332. this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
  4333. },
  4334. getValue : function() {
  4335. return this.hiddenField.dom.value;
  4336. },
  4337. onRowDblClick : function(vw, index, node, e) {
  4338. if (vw == this.toMultiselect.view){
  4339. this.toFrom();
  4340. } else if (vw == this.fromMultiselect.view) {
  4341. this.fromTo();
  4342. }
  4343. return this.fireEvent('rowdblclick', vw, index, node, e);
  4344. },
  4345. reset: function(){
  4346. range = this.toMultiselect.store.getRange();
  4347. this.toMultiselect.store.removeAll();
  4348. this.fromMultiselect.store.add(range);
  4349. var si = this.fromMultiselect.store.sortInfo;
  4350. if (si){
  4351. this.fromMultiselect.store.sort(si.field, si.direction);
  4352. }
  4353. this.valueChanged(this.toMultiselect.store);
  4354. }
  4355. });
  4356. Ext.reg('itemselector', Ext.ux.form.ItemSelector);
  4357. //backwards compat
  4358. Ext.ux.ItemSelector = Ext.ux.form.ItemSelector;
  4359. /*!
  4360. * Ext JS Library 3.3.0
  4361. * Copyright(c) 2006-2010 Ext JS, Inc.
  4362. * licensing@extjs.com
  4363. * http://www.extjs.com/license
  4364. */
  4365. Ext.ns('Ext.ux.grid');
  4366. Ext.ux.grid.LockingGridView = Ext.extend(Ext.grid.GridView, {
  4367. lockText : 'Lock',
  4368. unlockText : 'Unlock',
  4369. rowBorderWidth : 1,
  4370. lockedBorderWidth : 1,
  4371. /*
  4372. * This option ensures that height between the rows is synchronized
  4373. * between the locked and unlocked sides. This option only needs to be used
  4374. * when the row heights aren't predictable.
  4375. */
  4376. syncHeights: false,
  4377. initTemplates : function(){
  4378. var ts = this.templates || {};
  4379. if (!ts.masterTpl) {
  4380. ts.masterTpl = new Ext.Template(
  4381. '<div class="x-grid3" hidefocus="true">',
  4382. '<div class="x-grid3-locked">',
  4383. '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{lstyle}">{lockedHeader}</div></div><div class="x-clear"></div></div>',
  4384. '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{lstyle}">{lockedBody}</div><div class="x-grid3-scroll-spacer"></div></div>',
  4385. '</div>',
  4386. '<div class="x-grid3-viewport x-grid3-unlocked">',
  4387. '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
  4388. '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
  4389. '</div>',
  4390. '<div class="x-grid3-resize-marker">&#160;</div>',
  4391. '<div class="x-grid3-resize-proxy">&#160;</div>',
  4392. '</div>'
  4393. );
  4394. }
  4395. this.templates = ts;
  4396. Ext.ux.grid.LockingGridView.superclass.initTemplates.call(this);
  4397. },
  4398. getEditorParent : function(ed){
  4399. return this.el.dom;
  4400. },
  4401. initElements : function(){
  4402. var el = Ext.get(this.grid.getGridEl().dom.firstChild),
  4403. lockedWrap = el.child('div.x-grid3-locked'),
  4404. lockedHd = lockedWrap.child('div.x-grid3-header'),
  4405. lockedScroller = lockedWrap.child('div.x-grid3-scroller'),
  4406. mainWrap = el.child('div.x-grid3-viewport'),
  4407. mainHd = mainWrap.child('div.x-grid3-header'),
  4408. scroller = mainWrap.child('div.x-grid3-scroller');
  4409. if (this.grid.hideHeaders) {
  4410. lockedHd.setDisplayed(false);
  4411. mainHd.setDisplayed(false);
  4412. }
  4413. if(this.forceFit){
  4414. scroller.setStyle('overflow-x', 'hidden');
  4415. }
  4416. Ext.apply(this, {
  4417. el : el,
  4418. mainWrap: mainWrap,
  4419. mainHd : mainHd,
  4420. innerHd : mainHd.dom.firstChild,
  4421. scroller: scroller,
  4422. mainBody: scroller.child('div.x-grid3-body'),
  4423. focusEl : scroller.child('a'),
  4424. resizeMarker: el.child('div.x-grid3-resize-marker'),
  4425. resizeProxy : el.child('div.x-grid3-resize-proxy'),
  4426. lockedWrap: lockedWrap,
  4427. lockedHd: lockedHd,
  4428. lockedScroller: lockedScroller,
  4429. lockedBody: lockedScroller.child('div.x-grid3-body'),
  4430. lockedInnerHd: lockedHd.child('div.x-grid3-header-inner', true)
  4431. });
  4432. this.focusEl.swallowEvent('click', true);
  4433. },
  4434. getLockedRows : function(){
  4435. return this.hasRows() ? this.lockedBody.dom.childNodes : [];
  4436. },
  4437. getLockedRow : function(row){
  4438. return this.getLockedRows()[row];
  4439. },
  4440. getCell : function(row, col){
  4441. var lockedLen = this.cm.getLockedCount();
  4442. if(col < lockedLen){
  4443. return this.getLockedRow(row).getElementsByTagName('td')[col];
  4444. }
  4445. return Ext.ux.grid.LockingGridView.superclass.getCell.call(this, row, col - lockedLen);
  4446. },
  4447. getHeaderCell : function(index){
  4448. var lockedLen = this.cm.getLockedCount();
  4449. if(index < lockedLen){
  4450. return this.lockedHd.dom.getElementsByTagName('td')[index];
  4451. }
  4452. return Ext.ux.grid.LockingGridView.superclass.getHeaderCell.call(this, index - lockedLen);
  4453. },
  4454. addRowClass : function(row, cls){
  4455. var lockedRow = this.getLockedRow(row);
  4456. if(lockedRow){
  4457. this.fly(lockedRow).addClass(cls);
  4458. }
  4459. Ext.ux.grid.LockingGridView.superclass.addRowClass.call(this, row, cls);
  4460. },
  4461. removeRowClass : function(row, cls){
  4462. var lockedRow = this.getLockedRow(row);
  4463. if(lockedRow){
  4464. this.fly(lockedRow).removeClass(cls);
  4465. }
  4466. Ext.ux.grid.LockingGridView.superclass.removeRowClass.call(this, row, cls);
  4467. },
  4468. removeRow : function(row) {
  4469. Ext.removeNode(this.getLockedRow(row));
  4470. Ext.ux.grid.LockingGridView.superclass.removeRow.call(this, row);
  4471. },
  4472. removeRows : function(firstRow, lastRow){
  4473. var lockedBody = this.lockedBody.dom,
  4474. rowIndex = firstRow;
  4475. for(; rowIndex <= lastRow; rowIndex++){
  4476. Ext.removeNode(lockedBody.childNodes[firstRow]);
  4477. }
  4478. Ext.ux.grid.LockingGridView.superclass.removeRows.call(this, firstRow, lastRow);
  4479. },
  4480. syncScroll : function(e){
  4481. this.lockedScroller.dom.scrollTop = this.scroller.dom.scrollTop;
  4482. Ext.ux.grid.LockingGridView.superclass.syncScroll.call(this, e);
  4483. },
  4484. updateSortIcon : function(col, dir){
  4485. var sortClasses = this.sortClasses,
  4486. lockedHeaders = this.lockedHd.select('td').removeClass(sortClasses),
  4487. headers = this.mainHd.select('td').removeClass(sortClasses),
  4488. lockedLen = this.cm.getLockedCount(),
  4489. cls = sortClasses[dir == 'DESC' ? 1 : 0];
  4490. if(col < lockedLen){
  4491. lockedHeaders.item(col).addClass(cls);
  4492. }else{
  4493. headers.item(col - lockedLen).addClass(cls);
  4494. }
  4495. },
  4496. updateAllColumnWidths : function(){
  4497. var tw = this.getTotalWidth(),
  4498. clen = this.cm.getColumnCount(),
  4499. lw = this.getLockedWidth(),
  4500. llen = this.cm.getLockedCount(),
  4501. ws = [], len, i;
  4502. this.updateLockedWidth();
  4503. for(i = 0; i < clen; i++){
  4504. ws[i] = this.getColumnWidth(i);
  4505. var hd = this.getHeaderCell(i);
  4506. hd.style.width = ws[i];
  4507. }
  4508. var lns = this.getLockedRows(), ns = this.getRows(), row, trow, j;
  4509. for(i = 0, len = ns.length; i < len; i++){
  4510. row = lns[i];
  4511. row.style.width = lw;
  4512. if(row.firstChild){
  4513. row.firstChild.style.width = lw;
  4514. trow = row.firstChild.rows[0];
  4515. for (j = 0; j < llen; j++) {
  4516. trow.childNodes[j].style.width = ws[j];
  4517. }
  4518. }
  4519. row = ns[i];
  4520. row.style.width = tw;
  4521. if(row.firstChild){
  4522. row.firstChild.style.width = tw;
  4523. trow = row.firstChild.rows[0];
  4524. for (j = llen; j < clen; j++) {
  4525. trow.childNodes[j - llen].style.width = ws[j];
  4526. }
  4527. }
  4528. }
  4529. this.onAllColumnWidthsUpdated(ws, tw);
  4530. this.syncHeaderHeight();
  4531. },
  4532. updateColumnWidth : function(col, width){
  4533. var w = this.getColumnWidth(col),
  4534. llen = this.cm.getLockedCount(),
  4535. ns, rw, c, row;
  4536. this.updateLockedWidth();
  4537. if(col < llen){
  4538. ns = this.getLockedRows();
  4539. rw = this.getLockedWidth();
  4540. c = col;
  4541. }else{
  4542. ns = this.getRows();
  4543. rw = this.getTotalWidth();
  4544. c = col - llen;
  4545. }
  4546. var hd = this.getHeaderCell(col);
  4547. hd.style.width = w;
  4548. for(var i = 0, len = ns.length; i < len; i++){
  4549. row = ns[i];
  4550. row.style.width = rw;
  4551. if(row.firstChild){
  4552. row.firstChild.style.width = rw;
  4553. row.firstChild.rows[0].childNodes[c].style.width = w;
  4554. }
  4555. }
  4556. this.onColumnWidthUpdated(col, w, this.getTotalWidth());
  4557. this.syncHeaderHeight();
  4558. },
  4559. updateColumnHidden : function(col, hidden){
  4560. var llen = this.cm.getLockedCount(),
  4561. ns, rw, c, row,
  4562. display = hidden ? 'none' : '';
  4563. this.updateLockedWidth();
  4564. if(col < llen){
  4565. ns = this.getLockedRows();
  4566. rw = this.getLockedWidth();
  4567. c = col;
  4568. }else{
  4569. ns = this.getRows();
  4570. rw = this.getTotalWidth();
  4571. c = col - llen;
  4572. }
  4573. var hd = this.getHeaderCell(col);
  4574. hd.style.display = display;
  4575. for(var i = 0, len = ns.length; i < len; i++){
  4576. row = ns[i];
  4577. row.style.width = rw;
  4578. if(row.firstChild){
  4579. row.firstChild.style.width = rw;
  4580. row.firstChild.rows[0].childNodes[c].style.display = display;
  4581. }
  4582. }
  4583. this.onColumnHiddenUpdated(col, hidden, this.getTotalWidth());
  4584. delete this.lastViewWidth;
  4585. this.layout();
  4586. },
  4587. doRender : function(cs, rs, ds, startRow, colCount, stripe){
  4588. var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1,
  4589. tstyle = 'width:'+this.getTotalWidth()+';',
  4590. lstyle = 'width:'+this.getLockedWidth()+';',
  4591. buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r;
  4592. for(var j = 0, len = rs.length; j < len; j++){
  4593. r = rs[j]; cb = []; lcb = [];
  4594. var rowIndex = (j+startRow);
  4595. for(var i = 0; i < colCount; i++){
  4596. c = cs[i];
  4597. p.id = c.id;
  4598. p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
  4599. (this.cm.config[i].cellCls ? ' ' + this.cm.config[i].cellCls : '');
  4600. p.attr = p.cellAttr = '';
  4601. p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
  4602. p.style = c.style;
  4603. if(Ext.isEmpty(p.value)){
  4604. p.value = '&#160;';
  4605. }
  4606. if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){
  4607. p.css += ' x-grid3-dirty-cell';
  4608. }
  4609. if(c.locked){
  4610. lcb[lcb.length] = ct.apply(p);
  4611. }else{
  4612. cb[cb.length] = ct.apply(p);
  4613. }
  4614. }
  4615. var alt = [];
  4616. if(stripe && ((rowIndex+1) % 2 === 0)){
  4617. alt[0] = 'x-grid3-row-alt';
  4618. }
  4619. if(r.dirty){
  4620. alt[1] = ' x-grid3-dirty-row';
  4621. }
  4622. rp.cols = colCount;
  4623. if(this.getRowClass){
  4624. alt[2] = this.getRowClass(r, rowIndex, rp, ds);
  4625. }
  4626. rp.alt = alt.join(' ');
  4627. rp.cells = cb.join('');
  4628. rp.tstyle = tstyle;
  4629. buf[buf.length] = rt.apply(rp);
  4630. rp.cells = lcb.join('');
  4631. rp.tstyle = lstyle;
  4632. lbuf[lbuf.length] = rt.apply(rp);
  4633. }
  4634. return [buf.join(''), lbuf.join('')];
  4635. },
  4636. processRows : function(startRow, skipStripe){
  4637. if(!this.ds || this.ds.getCount() < 1){
  4638. return;
  4639. }
  4640. var rows = this.getRows(),
  4641. lrows = this.getLockedRows(),
  4642. row, lrow;
  4643. skipStripe = skipStripe || !this.grid.stripeRows;
  4644. startRow = startRow || 0;
  4645. for(var i = 0, len = rows.length; i < len; ++i){
  4646. row = rows[i];
  4647. lrow = lrows[i];
  4648. row.rowIndex = i;
  4649. lrow.rowIndex = i;
  4650. if(!skipStripe){
  4651. row.className = row.className.replace(this.rowClsRe, ' ');
  4652. lrow.className = lrow.className.replace(this.rowClsRe, ' ');
  4653. if ((i + 1) % 2 === 0){
  4654. row.className += ' x-grid3-row-alt';
  4655. lrow.className += ' x-grid3-row-alt';
  4656. }
  4657. }
  4658. this.syncRowHeights(row, lrow);
  4659. }
  4660. if(startRow === 0){
  4661. Ext.fly(rows[0]).addClass(this.firstRowCls);
  4662. Ext.fly(lrows[0]).addClass(this.firstRowCls);
  4663. }
  4664. Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
  4665. Ext.fly(lrows[lrows.length - 1]).addClass(this.lastRowCls);
  4666. },
  4667. syncRowHeights: function(row1, row2){
  4668. if(this.syncHeights){
  4669. var el1 = Ext.get(row1),
  4670. el2 = Ext.get(row2),
  4671. h1 = el1.getHeight(),
  4672. h2 = el2.getHeight();
  4673. if(h1 > h2){
  4674. el2.setHeight(h1);
  4675. }else if(h2 > h1){
  4676. el1.setHeight(h2);
  4677. }
  4678. }
  4679. },
  4680. afterRender : function(){
  4681. if(!this.ds || !this.cm){
  4682. return;
  4683. }
  4684. var bd = this.renderRows() || ['&#160;', '&#160;'];
  4685. this.mainBody.dom.innerHTML = bd[0];
  4686. this.lockedBody.dom.innerHTML = bd[1];
  4687. this.processRows(0, true);
  4688. if(this.deferEmptyText !== true){
  4689. this.applyEmptyText();
  4690. }
  4691. this.grid.fireEvent('viewready', this.grid);
  4692. },
  4693. renderUI : function(){
  4694. var templates = this.templates,
  4695. header = this.renderHeaders(),
  4696. body = templates.body.apply({rows:'&#160;'});
  4697. return templates.masterTpl.apply({
  4698. body : body,
  4699. header: header[0],
  4700. ostyle: 'width:' + this.getOffsetWidth() + ';',
  4701. bstyle: 'width:' + this.getTotalWidth() + ';',
  4702. lockedBody: body,
  4703. lockedHeader: header[1],
  4704. lstyle: 'width:'+this.getLockedWidth()+';'
  4705. });
  4706. },
  4707. afterRenderUI: function(){
  4708. var g = this.grid;
  4709. this.initElements();
  4710. Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
  4711. Ext.fly(this.lockedInnerHd).on('click', this.handleHdDown, this);
  4712. this.mainHd.on({
  4713. scope: this,
  4714. mouseover: this.handleHdOver,
  4715. mouseout: this.handleHdOut,
  4716. mousemove: this.handleHdMove
  4717. });
  4718. this.lockedHd.on({
  4719. scope: this,
  4720. mouseover: this.handleHdOver,
  4721. mouseout: this.handleHdOut,
  4722. mousemove: this.handleHdMove
  4723. });
  4724. this.scroller.on('scroll', this.syncScroll, this);
  4725. if(g.enableColumnResize !== false){
  4726. this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
  4727. this.splitZone.setOuterHandleElId(Ext.id(this.lockedHd.dom));
  4728. this.splitZone.setOuterHandleElId(Ext.id(this.mainHd.dom));
  4729. }
  4730. if(g.enableColumnMove){
  4731. this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
  4732. this.columnDrag.setOuterHandleElId(Ext.id(this.lockedInnerHd));
  4733. this.columnDrag.setOuterHandleElId(Ext.id(this.innerHd));
  4734. this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
  4735. }
  4736. if(g.enableHdMenu !== false){
  4737. this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
  4738. this.hmenu.add(
  4739. {itemId: 'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
  4740. {itemId: 'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
  4741. );
  4742. if(this.grid.enableColLock !== false){
  4743. this.hmenu.add('-',
  4744. {itemId: 'lock', text: this.lockText, cls: 'xg-hmenu-lock'},
  4745. {itemId: 'unlock', text: this.unlockText, cls: 'xg-hmenu-unlock'}
  4746. );
  4747. }
  4748. if(g.enableColumnHide !== false){
  4749. this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
  4750. this.colMenu.on({
  4751. scope: this,
  4752. beforeshow: this.beforeColMenuShow,
  4753. itemclick: this.handleHdMenuClick
  4754. });
  4755. this.hmenu.add('-', {
  4756. itemId:'columns',
  4757. hideOnClick: false,
  4758. text: this.columnsText,
  4759. menu: this.colMenu,
  4760. iconCls: 'x-cols-icon'
  4761. });
  4762. }
  4763. this.hmenu.on('itemclick', this.handleHdMenuClick, this);
  4764. }
  4765. if(g.trackMouseOver){
  4766. this.mainBody.on({
  4767. scope: this,
  4768. mouseover: this.onRowOver,
  4769. mouseout: this.onRowOut
  4770. });
  4771. this.lockedBody.on({
  4772. scope: this,
  4773. mouseover: this.onRowOver,
  4774. mouseout: this.onRowOut
  4775. });
  4776. }
  4777. if(g.enableDragDrop || g.enableDrag){
  4778. this.dragZone = new Ext.grid.GridDragZone(g, {
  4779. ddGroup : g.ddGroup || 'GridDD'
  4780. });
  4781. }
  4782. this.updateHeaderSortState();
  4783. },
  4784. layout : function(){
  4785. if(!this.mainBody){
  4786. return;
  4787. }
  4788. var g = this.grid;
  4789. var c = g.getGridEl();
  4790. var csize = c.getSize(true);
  4791. var vw = csize.width;
  4792. if(!g.hideHeaders && (vw < 20 || csize.height < 20)){
  4793. return;
  4794. }
  4795. this.syncHeaderHeight();
  4796. if(g.autoHeight){
  4797. this.scroller.dom.style.overflow = 'visible';
  4798. this.lockedScroller.dom.style.overflow = 'visible';
  4799. if(Ext.isWebKit){
  4800. this.scroller.dom.style.position = 'static';
  4801. this.lockedScroller.dom.style.position = 'static';
  4802. }
  4803. }else{
  4804. this.el.setSize(csize.width, csize.height);
  4805. var hdHeight = this.mainHd.getHeight();
  4806. var vh = csize.height - (hdHeight);
  4807. }
  4808. this.updateLockedWidth();
  4809. if(this.forceFit){
  4810. if(this.lastViewWidth != vw){
  4811. this.fitColumns(false, false);
  4812. this.lastViewWidth = vw;
  4813. }
  4814. }else {
  4815. this.autoExpand();
  4816. this.syncHeaderScroll();
  4817. }
  4818. this.onLayout(vw, vh);
  4819. },
  4820. getOffsetWidth : function() {
  4821. return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth() + this.getScrollOffset()) + 'px';
  4822. },
  4823. renderHeaders : function(){
  4824. var cm = this.cm,
  4825. ts = this.templates,
  4826. ct = ts.hcell,
  4827. cb = [], lcb = [],
  4828. p = {},
  4829. len = cm.getColumnCount(),
  4830. last = len - 1;
  4831. for(var i = 0; i < len; i++){
  4832. p.id = cm.getColumnId(i);
  4833. p.value = cm.getColumnHeader(i) || '';
  4834. p.style = this.getColumnStyle(i, true);
  4835. p.tooltip = this.getColumnTooltip(i);
  4836. p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
  4837. (cm.config[i].headerCls ? ' ' + cm.config[i].headerCls : '');
  4838. if(cm.config[i].align == 'right'){
  4839. p.istyle = 'padding-right:16px';
  4840. } else {
  4841. delete p.istyle;
  4842. }
  4843. if(cm.isLocked(i)){
  4844. lcb[lcb.length] = ct.apply(p);
  4845. }else{
  4846. cb[cb.length] = ct.apply(p);
  4847. }
  4848. }
  4849. return [ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'}),
  4850. ts.header.apply({cells: lcb.join(''), tstyle:'width:'+this.getLockedWidth()+';'})];
  4851. },
  4852. updateHeaders : function(){
  4853. var hd = this.renderHeaders();
  4854. this.innerHd.firstChild.innerHTML = hd[0];
  4855. this.innerHd.firstChild.style.width = this.getOffsetWidth();
  4856. this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
  4857. this.lockedInnerHd.firstChild.innerHTML = hd[1];
  4858. var lw = this.getLockedWidth();
  4859. this.lockedInnerHd.firstChild.style.width = lw;
  4860. this.lockedInnerHd.firstChild.firstChild.style.width = lw;
  4861. },
  4862. getResolvedXY : function(resolved){
  4863. if(!resolved){
  4864. return null;
  4865. }
  4866. var c = resolved.cell, r = resolved.row;
  4867. return c ? Ext.fly(c).getXY() : [this.scroller.getX(), Ext.fly(r).getY()];
  4868. },
  4869. syncFocusEl : function(row, col, hscroll){
  4870. Ext.ux.grid.LockingGridView.superclass.syncFocusEl.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
  4871. },
  4872. ensureVisible : function(row, col, hscroll){
  4873. return Ext.ux.grid.LockingGridView.superclass.ensureVisible.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
  4874. },
  4875. insertRows : function(dm, firstRow, lastRow, isUpdate){
  4876. var last = dm.getCount() - 1;
  4877. if(!isUpdate && firstRow === 0 && lastRow >= last){
  4878. this.refresh();
  4879. }else{
  4880. if(!isUpdate){
  4881. this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
  4882. }
  4883. var html = this.renderRows(firstRow, lastRow),
  4884. before = this.getRow(firstRow);
  4885. if(before){
  4886. if(firstRow === 0){
  4887. this.removeRowClass(0, this.firstRowCls);
  4888. }
  4889. Ext.DomHelper.insertHtml('beforeBegin', before, html[0]);
  4890. before = this.getLockedRow(firstRow);
  4891. Ext.DomHelper.insertHtml('beforeBegin', before, html[1]);
  4892. }else{
  4893. this.removeRowClass(last - 1, this.lastRowCls);
  4894. Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html[0]);
  4895. Ext.DomHelper.insertHtml('beforeEnd', this.lockedBody.dom, html[1]);
  4896. }
  4897. if(!isUpdate){
  4898. this.fireEvent('rowsinserted', this, firstRow, lastRow);
  4899. this.processRows(firstRow);
  4900. }else if(firstRow === 0 || firstRow >= last){
  4901. this.addRowClass(firstRow, firstRow === 0 ? this.firstRowCls : this.lastRowCls);
  4902. }
  4903. }
  4904. this.syncFocusEl(firstRow);
  4905. },
  4906. getColumnStyle : function(col, isHeader){
  4907. var style = !isHeader ? this.cm.config[col].cellStyle || this.cm.config[col].css || '' : this.cm.config[col].headerStyle || '';
  4908. style += 'width:'+this.getColumnWidth(col)+';';
  4909. if(this.cm.isHidden(col)){
  4910. style += 'display:none;';
  4911. }
  4912. var align = this.cm.config[col].align;
  4913. if(align){
  4914. style += 'text-align:'+align+';';
  4915. }
  4916. return style;
  4917. },
  4918. getLockedWidth : function() {
  4919. return this.cm.getTotalLockedWidth() + 'px';
  4920. },
  4921. getTotalWidth : function() {
  4922. return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth()) + 'px';
  4923. },
  4924. getColumnData : function(){
  4925. var cs = [], cm = this.cm, colCount = cm.getColumnCount();
  4926. for(var i = 0; i < colCount; i++){
  4927. var name = cm.getDataIndex(i);
  4928. cs[i] = {
  4929. name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
  4930. renderer : cm.getRenderer(i),
  4931. id : cm.getColumnId(i),
  4932. style : this.getColumnStyle(i),
  4933. locked : cm.isLocked(i)
  4934. };
  4935. }
  4936. return cs;
  4937. },
  4938. renderBody : function(){
  4939. var markup = this.renderRows() || ['&#160;', '&#160;'];
  4940. return [this.templates.body.apply({rows: markup[0]}), this.templates.body.apply({rows: markup[1]})];
  4941. },
  4942. refreshRow: function(record){
  4943. var store = this.ds,
  4944. colCount = this.cm.getColumnCount(),
  4945. columns = this.getColumnData(),
  4946. last = colCount - 1,
  4947. cls = ['x-grid3-row'],
  4948. rowParams = {
  4949. tstyle: String.format("width: {0};", this.getTotalWidth())
  4950. },
  4951. lockedRowParams = {
  4952. tstyle: String.format("width: {0};", this.getLockedWidth())
  4953. },
  4954. colBuffer = [],
  4955. lockedColBuffer = [],
  4956. cellTpl = this.templates.cell,
  4957. rowIndex,
  4958. row,
  4959. lockedRow,
  4960. column,
  4961. meta,
  4962. css,
  4963. i;
  4964. if (Ext.isNumber(record)) {
  4965. rowIndex = record;
  4966. record = store.getAt(rowIndex);
  4967. } else {
  4968. rowIndex = store.indexOf(record);
  4969. }
  4970. if (!record || rowIndex < 0) {
  4971. return;
  4972. }
  4973. for (i = 0; i < colCount; i++) {
  4974. column = columns[i];
  4975. if (i == 0) {
  4976. css = 'x-grid3-cell-first';
  4977. } else {
  4978. css = (i == last) ? 'x-grid3-cell-last ' : '';
  4979. }
  4980. meta = {
  4981. id: column.id,
  4982. style: column.style,
  4983. css: css,
  4984. attr: "",
  4985. cellAttr: ""
  4986. };
  4987. meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
  4988. if (Ext.isEmpty(meta.value)) {
  4989. meta.value = ' ';
  4990. }
  4991. if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
  4992. meta.css += ' x-grid3-dirty-cell';
  4993. }
  4994. if (column.locked) {
  4995. lockedColBuffer[i] = cellTpl.apply(meta);
  4996. } else {
  4997. colBuffer[i] = cellTpl.apply(meta);
  4998. }
  4999. }
  5000. row = this.getRow(rowIndex);
  5001. row.className = '';
  5002. lockedRow = this.getLockedRow(rowIndex);
  5003. lockedRow.className = '';
  5004. if (this.grid.stripeRows && ((rowIndex + 1) % 2 === 0)) {
  5005. cls.push('x-grid3-row-alt');
  5006. }
  5007. if (this.getRowClass) {
  5008. rowParams.cols = colCount;
  5009. cls.push(this.getRowClass(record, rowIndex, rowParams, store));
  5010. }
  5011. // Unlocked rows
  5012. this.fly(row).addClass(cls).setStyle(rowParams.tstyle);
  5013. rowParams.cells = colBuffer.join("");
  5014. row.innerHTML = this.templates.rowInner.apply(rowParams);
  5015. // Locked rows
  5016. this.fly(lockedRow).addClass(cls).setStyle(lockedRowParams.tstyle);
  5017. lockedRowParams.cells = lockedColBuffer.join("");
  5018. lockedRow.innerHTML = this.templates.rowInner.apply(lockedRowParams);
  5019. lockedRow.rowIndex = rowIndex;
  5020. this.syncRowHeights(row, lockedRow);
  5021. this.fireEvent('rowupdated', this, rowIndex, record);
  5022. },
  5023. refresh : function(headersToo){
  5024. this.fireEvent('beforerefresh', this);
  5025. this.grid.stopEditing(true);
  5026. var result = this.renderBody();
  5027. this.mainBody.update(result[0]).setWidth(this.getTotalWidth());
  5028. this.lockedBody.update(result[1]).setWidth(this.getLockedWidth());
  5029. if(headersToo === true){
  5030. this.updateHeaders();
  5031. this.updateHeaderSortState();
  5032. }
  5033. this.processRows(0, true);
  5034. this.layout();
  5035. this.applyEmptyText();
  5036. this.fireEvent('refresh', this);
  5037. },
  5038. onDenyColumnLock : function(){
  5039. },
  5040. initData : function(ds, cm){
  5041. if(this.cm){
  5042. this.cm.un('columnlockchange', this.onColumnLock, this);
  5043. }
  5044. Ext.ux.grid.LockingGridView.superclass.initData.call(this, ds, cm);
  5045. if(this.cm){
  5046. this.cm.on('columnlockchange', this.onColumnLock, this);
  5047. }
  5048. },
  5049. onColumnLock : function(){
  5050. this.refresh(true);
  5051. },
  5052. handleHdMenuClick : function(item){
  5053. var index = this.hdCtxIndex,
  5054. cm = this.cm,
  5055. id = item.getItemId(),
  5056. llen = cm.getLockedCount();
  5057. switch(id){
  5058. case 'lock':
  5059. if(cm.getColumnCount(true) <= llen + 1){
  5060. this.onDenyColumnLock();
  5061. return undefined;
  5062. }
  5063. cm.setLocked(index, true);
  5064. if(llen != index){
  5065. cm.moveColumn(index, llen);
  5066. this.grid.fireEvent('columnmove', index, llen);
  5067. }
  5068. break;
  5069. case 'unlock':
  5070. if(llen - 1 != index){
  5071. cm.setLocked(index, false, true);
  5072. cm.moveColumn(index, llen - 1);
  5073. this.grid.fireEvent('columnmove', index, llen - 1);
  5074. }else{
  5075. cm.setLocked(index, false);
  5076. }
  5077. break;
  5078. default:
  5079. return Ext.ux.grid.LockingGridView.superclass.handleHdMenuClick.call(this, item);
  5080. }
  5081. return true;
  5082. },
  5083. handleHdDown : function(e, t){
  5084. Ext.ux.grid.LockingGridView.superclass.handleHdDown.call(this, e, t);
  5085. if(this.grid.enableColLock !== false){
  5086. if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
  5087. var hd = this.findHeaderCell(t),
  5088. index = this.getCellIndex(hd),
  5089. ms = this.hmenu.items, cm = this.cm;
  5090. ms.get('lock').setDisabled(cm.isLocked(index));
  5091. ms.get('unlock').setDisabled(!cm.isLocked(index));
  5092. }
  5093. }
  5094. },
  5095. syncHeaderHeight: function(){
  5096. var hrow = Ext.fly(this.innerHd).child('tr', true),
  5097. lhrow = Ext.fly(this.lockedInnerHd).child('tr', true);
  5098. hrow.style.height = 'auto';
  5099. lhrow.style.height = 'auto';
  5100. var hd = hrow.offsetHeight,
  5101. lhd = lhrow.offsetHeight,
  5102. height = Math.max(lhd, hd) + 'px';
  5103. hrow.style.height = height;
  5104. lhrow.style.height = height;
  5105. },
  5106. updateLockedWidth: function(){
  5107. var lw = this.cm.getTotalLockedWidth(),
  5108. tw = this.cm.getTotalWidth() - lw,
  5109. csize = this.grid.getGridEl().getSize(true),
  5110. lp = Ext.isBorderBox ? 0 : this.lockedBorderWidth,
  5111. rp = Ext.isBorderBox ? 0 : this.rowBorderWidth,
  5112. vw = (csize.width - lw - lp - rp) + 'px',
  5113. so = this.getScrollOffset();
  5114. if(!this.grid.autoHeight){
  5115. var vh = (csize.height - this.mainHd.getHeight()) + 'px';
  5116. this.lockedScroller.dom.style.height = vh;
  5117. this.scroller.dom.style.height = vh;
  5118. }
  5119. this.lockedWrap.dom.style.width = (lw + rp) + 'px';
  5120. this.scroller.dom.style.width = vw;
  5121. this.mainWrap.dom.style.left = (lw + lp + rp) + 'px';
  5122. if(this.innerHd){
  5123. this.lockedInnerHd.firstChild.style.width = lw + 'px';
  5124. this.lockedInnerHd.firstChild.firstChild.style.width = lw + 'px';
  5125. this.innerHd.style.width = vw;
  5126. this.innerHd.firstChild.style.width = (tw + rp + so) + 'px';
  5127. this.innerHd.firstChild.firstChild.style.width = tw + 'px';
  5128. }
  5129. if(this.mainBody){
  5130. this.lockedBody.dom.style.width = (lw + rp) + 'px';
  5131. this.mainBody.dom.style.width = (tw + rp) + 'px';
  5132. }
  5133. }
  5134. });
  5135. Ext.ux.grid.LockingColumnModel = Ext.extend(Ext.grid.ColumnModel, {
  5136. /**
  5137. * Returns true if the given column index is currently locked
  5138. * @param {Number} colIndex The column index
  5139. * @return {Boolean} True if the column is locked
  5140. */
  5141. isLocked : function(colIndex){
  5142. return this.config[colIndex].locked === true;
  5143. },
  5144. /**
  5145. * Locks or unlocks a given column
  5146. * @param {Number} colIndex The column index
  5147. * @param {Boolean} value True to lock, false to unlock
  5148. * @param {Boolean} suppressEvent Pass false to cause the columnlockchange event not to fire
  5149. */
  5150. setLocked : function(colIndex, value, suppressEvent){
  5151. if (this.isLocked(colIndex) == value) {
  5152. return;
  5153. }
  5154. this.config[colIndex].locked = value;
  5155. if (!suppressEvent) {
  5156. this.fireEvent('columnlockchange', this, colIndex, value);
  5157. }
  5158. },
  5159. /**
  5160. * Returns the total width of all locked columns
  5161. * @return {Number} The width of all locked columns
  5162. */
  5163. getTotalLockedWidth : function(){
  5164. var totalWidth = 0;
  5165. for (var i = 0, len = this.config.length; i < len; i++) {
  5166. if (this.isLocked(i) && !this.isHidden(i)) {
  5167. totalWidth += this.getColumnWidth(i);
  5168. }
  5169. }
  5170. return totalWidth;
  5171. },
  5172. /**
  5173. * Returns the total number of locked columns
  5174. * @return {Number} The number of locked columns
  5175. */
  5176. getLockedCount : function() {
  5177. var len = this.config.length;
  5178. for (var i = 0; i < len; i++) {
  5179. if (!this.isLocked(i)) {
  5180. return i;
  5181. }
  5182. }
  5183. //if we get to this point all of the columns are locked so we return the total
  5184. return len;
  5185. },
  5186. /**
  5187. * Moves a column from one position to another
  5188. * @param {Number} oldIndex The current column index
  5189. * @param {Number} newIndex The destination column index
  5190. */
  5191. moveColumn : function(oldIndex, newIndex){
  5192. var oldLocked = this.isLocked(oldIndex),
  5193. newLocked = this.isLocked(newIndex);
  5194. if (oldIndex < newIndex && oldLocked && !newLocked) {
  5195. this.setLocked(oldIndex, false, true);
  5196. } else if (oldIndex > newIndex && !oldLocked && newLocked) {
  5197. this.setLocked(oldIndex, true, true);
  5198. }
  5199. Ext.ux.grid.LockingColumnModel.superclass.moveColumn.apply(this, arguments);
  5200. }
  5201. });Ext.ns('Ext.ux.form');
  5202. /**
  5203. * @class Ext.ux.form.MultiSelect
  5204. * @extends Ext.form.Field
  5205. * A control that allows selection and form submission of multiple list items.
  5206. *
  5207. * @history
  5208. * 2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
  5209. * 2008-06-19 bpm Docs and demo code clean up
  5210. *
  5211. * @constructor
  5212. * Create a new MultiSelect
  5213. * @param {Object} config Configuration options
  5214. * @xtype multiselect
  5215. */
  5216. Ext.ux.form.MultiSelect = Ext.extend(Ext.form.Field, {
  5217. /**
  5218. * @cfg {String} legend Wraps the object with a fieldset and specified legend.
  5219. */
  5220. /**
  5221. * @cfg {Ext.ListView} view The {@link Ext.ListView} used to render the multiselect list.
  5222. */
  5223. /**
  5224. * @cfg {String/Array} dragGroup The ddgroup name(s) for the MultiSelect DragZone (defaults to undefined).
  5225. */
  5226. /**
  5227. * @cfg {String/Array} dropGroup The ddgroup name(s) for the MultiSelect DropZone (defaults to undefined).
  5228. */
  5229. /**
  5230. * @cfg {Boolean} ddReorder Whether the items in the MultiSelect list are drag/drop reorderable (defaults to false).
  5231. */
  5232. ddReorder:false,
  5233. /**
  5234. * @cfg {Object/Array} tbar The top toolbar of the control. This can be a {@link Ext.Toolbar} object, a
  5235. * toolbar config, or an array of buttons/button configs to be added to the toolbar.
  5236. */
  5237. /**
  5238. * @cfg {String} appendOnly True if the list should only allow append drops when drag/drop is enabled
  5239. * (use for lists which are sorted, defaults to false).
  5240. */
  5241. appendOnly:false,
  5242. /**
  5243. * @cfg {Number} width Width in pixels of the control (defaults to 100).
  5244. */
  5245. width:100,
  5246. /**
  5247. * @cfg {Number} height Height in pixels of the control (defaults to 100).
  5248. */
  5249. height:100,
  5250. /**
  5251. * @cfg {String/Number} displayField Name/Index of the desired display field in the dataset (defaults to 0).
  5252. */
  5253. displayField:0,
  5254. /**
  5255. * @cfg {String/Number} valueField Name/Index of the desired value field in the dataset (defaults to 1).
  5256. */
  5257. valueField:1,
  5258. /**
  5259. * @cfg {Boolean} allowBlank False to require at least one item in the list to be selected, true to allow no
  5260. * selection (defaults to true).
  5261. */
  5262. allowBlank:true,
  5263. /**
  5264. * @cfg {Number} minSelections Minimum number of selections allowed (defaults to 0).
  5265. */
  5266. minSelections:0,
  5267. /**
  5268. * @cfg {Number} maxSelections Maximum number of selections allowed (defaults to Number.MAX_VALUE).
  5269. */
  5270. maxSelections:Number.MAX_VALUE,
  5271. /**
  5272. * @cfg {String} blankText Default text displayed when the control contains no items (defaults to the same value as
  5273. * {@link Ext.form.TextField#blankText}.
  5274. */
  5275. blankText:Ext.form.TextField.prototype.blankText,
  5276. /**
  5277. * @cfg {String} minSelectionsText Validation message displayed when {@link #minSelections} is not met (defaults to 'Minimum {0}
  5278. * item(s) required'). The {0} token will be replaced by the value of {@link #minSelections}.
  5279. */
  5280. minSelectionsText:'Minimum {0} item(s) required',
  5281. /**
  5282. * @cfg {String} maxSelectionsText Validation message displayed when {@link #maxSelections} is not met (defaults to 'Maximum {0}
  5283. * item(s) allowed'). The {0} token will be replaced by the value of {@link #maxSelections}.
  5284. */
  5285. maxSelectionsText:'Maximum {0} item(s) allowed',
  5286. /**
  5287. * @cfg {String} delimiter The string used to delimit between items when set or returned as a string of values
  5288. * (defaults to ',').
  5289. */
  5290. delimiter:',',
  5291. /**
  5292. * @cfg {Ext.data.Store/Array} store The data source to which this MultiSelect is bound (defaults to <tt>undefined</tt>).
  5293. * Acceptable values for this property are:
  5294. * <div class="mdetail-params"><ul>
  5295. * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
  5296. * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally.
  5297. * <div class="mdetail-params"><ul>
  5298. * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
  5299. * A 1-dimensional array will automatically be expanded (each array item will be the combo
  5300. * {@link #valueField value} and {@link #displayField text})</div></li>
  5301. * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
  5302. * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
  5303. * {@link #valueField value}, while the value at index 1 is assumed to be the combo {@link #displayField text}.
  5304. * </div></li></ul></div></li></ul></div>
  5305. */
  5306. // private
  5307. defaultAutoCreate : {tag: "div"},
  5308. // private
  5309. initComponent: function(){
  5310. Ext.ux.form.MultiSelect.superclass.initComponent.call(this);
  5311. if(Ext.isArray(this.store)){
  5312. if (Ext.isArray(this.store[0])){
  5313. this.store = new Ext.data.ArrayStore({
  5314. fields: ['value','text'],
  5315. data: this.store
  5316. });
  5317. this.valueField = 'value';
  5318. }else{
  5319. this.store = new Ext.data.ArrayStore({
  5320. fields: ['text'],
  5321. data: this.store,
  5322. expandData: true
  5323. });
  5324. this.valueField = 'text';
  5325. }
  5326. this.displayField = 'text';
  5327. } else {
  5328. this.store = Ext.StoreMgr.lookup(this.store);
  5329. }
  5330. this.addEvents({
  5331. 'dblclick' : true,
  5332. 'click' : true,
  5333. 'change' : true,
  5334. 'drop' : true
  5335. });
  5336. },
  5337. // private
  5338. onRender: function(ct, position){
  5339. Ext.ux.form.MultiSelect.superclass.onRender.call(this, ct, position);
  5340. var fs = this.fs = new Ext.form.FieldSet({
  5341. renderTo: this.el,
  5342. title: this.legend,
  5343. height: this.height,
  5344. width: this.width,
  5345. style: "padding:0;",
  5346. tbar: this.tbar
  5347. });
  5348. fs.body.addClass('ux-mselect');
  5349. this.view = new Ext.ListView({
  5350. multiSelect: true,
  5351. store: this.store,
  5352. columns: [{ header: 'Value', width: 1, dataIndex: this.displayField }],
  5353. hideHeaders: true
  5354. });
  5355. fs.add(this.view);
  5356. this.view.on('click', this.onViewClick, this);
  5357. this.view.on('beforeclick', this.onViewBeforeClick, this);
  5358. this.view.on('dblclick', this.onViewDblClick, this);
  5359. this.hiddenName = this.name || Ext.id();
  5360. var hiddenTag = { tag: "input", type: "hidden", value: "", name: this.hiddenName };
  5361. this.hiddenField = this.el.createChild(hiddenTag);
  5362. this.hiddenField.dom.disabled = this.hiddenName != this.name;
  5363. fs.doLayout();
  5364. },
  5365. // private
  5366. afterRender: function(){
  5367. Ext.ux.form.MultiSelect.superclass.afterRender.call(this);
  5368. if (this.ddReorder && !this.dragGroup && !this.dropGroup){
  5369. this.dragGroup = this.dropGroup = 'MultiselectDD-' + Ext.id();
  5370. }
  5371. if (this.draggable || this.dragGroup){
  5372. this.dragZone = new Ext.ux.form.MultiSelect.DragZone(this, {
  5373. ddGroup: this.dragGroup
  5374. });
  5375. }
  5376. if (this.droppable || this.dropGroup){
  5377. this.dropZone = new Ext.ux.form.MultiSelect.DropZone(this, {
  5378. ddGroup: this.dropGroup
  5379. });
  5380. }
  5381. },
  5382. // private
  5383. onViewClick: function(vw, index, node, e) {
  5384. this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
  5385. this.hiddenField.dom.value = this.getValue();
  5386. this.fireEvent('click', this, e);
  5387. this.validate();
  5388. },
  5389. // private
  5390. onViewBeforeClick: function(vw, index, node, e) {
  5391. if (this.disabled || this.readOnly) {
  5392. return false;
  5393. }
  5394. },
  5395. // private
  5396. onViewDblClick : function(vw, index, node, e) {
  5397. return this.fireEvent('dblclick', vw, index, node, e);
  5398. },
  5399. /**
  5400. * Returns an array of data values for the selected items in the list. The values will be separated
  5401. * by {@link #delimiter}.
  5402. * @return {Array} value An array of string data values
  5403. */
  5404. getValue: function(valueField){
  5405. var returnArray = [];
  5406. var selectionsArray = this.view.getSelectedIndexes();
  5407. if (selectionsArray.length == 0) {return '';}
  5408. for (var i=0; i<selectionsArray.length; i++) {
  5409. returnArray.push(this.store.getAt(selectionsArray[i]).get((valueField != null) ? valueField : this.valueField));
  5410. }
  5411. return returnArray.join(this.delimiter);
  5412. },
  5413. /**
  5414. * Sets a delimited string (using {@link #delimiter}) or array of data values into the list.
  5415. * @param {String/Array} values The values to set
  5416. */
  5417. setValue: function(values) {
  5418. var index;
  5419. var selections = [];
  5420. this.view.clearSelections();
  5421. this.hiddenField.dom.value = '';
  5422. if (!values || (values == '')) { return; }
  5423. if (!Ext.isArray(values)) { values = values.split(this.delimiter); }
  5424. for (var i=0; i<values.length; i++) {
  5425. index = this.view.store.indexOf(this.view.store.query(this.valueField,
  5426. new RegExp('^' + values[i] + '$', "i")).itemAt(0));
  5427. selections.push(index);
  5428. }
  5429. this.view.select(selections);
  5430. this.hiddenField.dom.value = this.getValue();
  5431. this.validate();
  5432. },
  5433. // inherit docs
  5434. reset : function() {
  5435. this.setValue('');
  5436. },
  5437. // inherit docs
  5438. getRawValue: function(valueField) {
  5439. var tmp = this.getValue(valueField);
  5440. if (tmp.length) {
  5441. tmp = tmp.split(this.delimiter);
  5442. }
  5443. else {
  5444. tmp = [];
  5445. }
  5446. return tmp;
  5447. },
  5448. // inherit docs
  5449. setRawValue: function(values){
  5450. setValue(values);
  5451. },
  5452. // inherit docs
  5453. validateValue : function(value){
  5454. if (value.length < 1) { // if it has no value
  5455. if (this.allowBlank) {
  5456. this.clearInvalid();
  5457. return true;
  5458. } else {
  5459. this.markInvalid(this.blankText);
  5460. return false;
  5461. }
  5462. }
  5463. if (value.length < this.minSelections) {
  5464. this.markInvalid(String.format(this.minSelectionsText, this.minSelections));
  5465. return false;
  5466. }
  5467. if (value.length > this.maxSelections) {
  5468. this.markInvalid(String.format(this.maxSelectionsText, this.maxSelections));
  5469. return false;
  5470. }
  5471. return true;
  5472. },
  5473. // inherit docs
  5474. disable: function(){
  5475. this.disabled = true;
  5476. this.hiddenField.dom.disabled = true;
  5477. this.fs.disable();
  5478. },
  5479. // inherit docs
  5480. enable: function(){
  5481. this.disabled = false;
  5482. this.hiddenField.dom.disabled = false;
  5483. this.fs.enable();
  5484. },
  5485. // inherit docs
  5486. destroy: function(){
  5487. Ext.destroy(this.fs, this.dragZone, this.dropZone);
  5488. Ext.ux.form.MultiSelect.superclass.destroy.call(this);
  5489. }
  5490. });
  5491. Ext.reg('multiselect', Ext.ux.form.MultiSelect);
  5492. //backwards compat
  5493. Ext.ux.Multiselect = Ext.ux.form.MultiSelect;
  5494. Ext.ux.form.MultiSelect.DragZone = function(ms, config){
  5495. this.ms = ms;
  5496. this.view = ms.view;
  5497. var ddGroup = config.ddGroup || 'MultiselectDD';
  5498. var dd;
  5499. if (Ext.isArray(ddGroup)){
  5500. dd = ddGroup.shift();
  5501. } else {
  5502. dd = ddGroup;
  5503. ddGroup = null;
  5504. }
  5505. Ext.ux.form.MultiSelect.DragZone.superclass.constructor.call(this, this.ms.fs.body, { containerScroll: true, ddGroup: dd });
  5506. this.setDraggable(ddGroup);
  5507. };
  5508. Ext.extend(Ext.ux.form.MultiSelect.DragZone, Ext.dd.DragZone, {
  5509. onInitDrag : function(x, y){
  5510. var el = Ext.get(this.dragData.ddel.cloneNode(true));
  5511. this.proxy.update(el.dom);
  5512. el.setWidth(el.child('em').getWidth());
  5513. this.onStartDrag(x, y);
  5514. return true;
  5515. },
  5516. // private
  5517. collectSelection: function(data) {
  5518. data.repairXY = Ext.fly(this.view.getSelectedNodes()[0]).getXY();
  5519. var i = 0;
  5520. this.view.store.each(function(rec){
  5521. if (this.view.isSelected(i)) {
  5522. var n = this.view.getNode(i);
  5523. var dragNode = n.cloneNode(true);
  5524. dragNode.id = Ext.id();
  5525. data.ddel.appendChild(dragNode);
  5526. data.records.push(this.view.store.getAt(i));
  5527. data.viewNodes.push(n);
  5528. }
  5529. i++;
  5530. }, this);
  5531. },
  5532. // override
  5533. onEndDrag: function(data, e) {
  5534. var d = Ext.get(this.dragData.ddel);
  5535. if (d && d.hasClass("multi-proxy")) {
  5536. d.remove();
  5537. }
  5538. },
  5539. // override
  5540. getDragData: function(e){
  5541. var target = this.view.findItemFromChild(e.getTarget());
  5542. if(target) {
  5543. if (!this.view.isSelected(target) && !e.ctrlKey && !e.shiftKey) {
  5544. this.view.select(target);
  5545. this.ms.setValue(this.ms.getValue());
  5546. }
  5547. if (this.view.getSelectionCount() == 0 || e.ctrlKey || e.shiftKey) return false;
  5548. var dragData = {
  5549. sourceView: this.view,
  5550. viewNodes: [],
  5551. records: []
  5552. };
  5553. if (this.view.getSelectionCount() == 1) {
  5554. var i = this.view.getSelectedIndexes()[0];
  5555. var n = this.view.getNode(i);
  5556. dragData.viewNodes.push(dragData.ddel = n);
  5557. dragData.records.push(this.view.store.getAt(i));
  5558. dragData.repairXY = Ext.fly(n).getXY();
  5559. } else {
  5560. dragData.ddel = document.createElement('div');
  5561. dragData.ddel.className = 'multi-proxy';
  5562. this.collectSelection(dragData);
  5563. }
  5564. return dragData;
  5565. }
  5566. return false;
  5567. },
  5568. // override the default repairXY.
  5569. getRepairXY : function(e){
  5570. return this.dragData.repairXY;
  5571. },
  5572. // private
  5573. setDraggable: function(ddGroup){
  5574. if (!ddGroup) return;
  5575. if (Ext.isArray(ddGroup)) {
  5576. Ext.each(ddGroup, this.setDraggable, this);
  5577. return;
  5578. }
  5579. this.addToGroup(ddGroup);
  5580. }
  5581. });
  5582. Ext.ux.form.MultiSelect.DropZone = function(ms, config){
  5583. this.ms = ms;
  5584. this.view = ms.view;
  5585. var ddGroup = config.ddGroup || 'MultiselectDD';
  5586. var dd;
  5587. if (Ext.isArray(ddGroup)){
  5588. dd = ddGroup.shift();
  5589. } else {
  5590. dd = ddGroup;
  5591. ddGroup = null;
  5592. }
  5593. Ext.ux.form.MultiSelect.DropZone.superclass.constructor.call(this, this.ms.fs.body, { containerScroll: true, ddGroup: dd });
  5594. this.setDroppable(ddGroup);
  5595. };
  5596. Ext.extend(Ext.ux.form.MultiSelect.DropZone, Ext.dd.DropZone, {
  5597. /**
  5598. * Part of the Ext.dd.DropZone interface. If no target node is found, the
  5599. * whole Element becomes the target, and this causes the drop gesture to append.
  5600. */
  5601. getTargetFromEvent : function(e) {
  5602. var target = e.getTarget();
  5603. return target;
  5604. },
  5605. // private
  5606. getDropPoint : function(e, n, dd){
  5607. if (n == this.ms.fs.body.dom) { return "below"; }
  5608. var t = Ext.lib.Dom.getY(n), b = t + n.offsetHeight;
  5609. var c = t + (b - t) / 2;
  5610. var y = Ext.lib.Event.getPageY(e);
  5611. if(y <= c) {
  5612. return "above";
  5613. }else{
  5614. return "below";
  5615. }
  5616. },
  5617. // private
  5618. isValidDropPoint: function(pt, n, data) {
  5619. if (!data.viewNodes || (data.viewNodes.length != 1)) {
  5620. return true;
  5621. }
  5622. var d = data.viewNodes[0];
  5623. if (d == n) {
  5624. return false;
  5625. }
  5626. if ((pt == "below") && (n.nextSibling == d)) {
  5627. return false;
  5628. }
  5629. if ((pt == "above") && (n.previousSibling == d)) {
  5630. return false;
  5631. }
  5632. return true;
  5633. },
  5634. // override
  5635. onNodeEnter : function(n, dd, e, data){
  5636. return false;
  5637. },
  5638. // override
  5639. onNodeOver : function(n, dd, e, data){
  5640. var dragElClass = this.dropNotAllowed;
  5641. var pt = this.getDropPoint(e, n, dd);
  5642. if (this.isValidDropPoint(pt, n, data)) {
  5643. if (this.ms.appendOnly) {
  5644. return "x-tree-drop-ok-below";
  5645. }
  5646. // set the insert point style on the target node
  5647. if (pt) {
  5648. var targetElClass;
  5649. if (pt == "above"){
  5650. dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
  5651. targetElClass = "x-view-drag-insert-above";
  5652. } else {
  5653. dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
  5654. targetElClass = "x-view-drag-insert-below";
  5655. }
  5656. if (this.lastInsertClass != targetElClass){
  5657. Ext.fly(n).replaceClass(this.lastInsertClass, targetElClass);
  5658. this.lastInsertClass = targetElClass;
  5659. }
  5660. }
  5661. }
  5662. return dragElClass;
  5663. },
  5664. // private
  5665. onNodeOut : function(n, dd, e, data){
  5666. this.removeDropIndicators(n);
  5667. },
  5668. // private
  5669. onNodeDrop : function(n, dd, e, data){
  5670. if (this.ms.fireEvent("drop", this, n, dd, e, data) === false) {
  5671. return false;
  5672. }
  5673. var pt = this.getDropPoint(e, n, dd);
  5674. if (n != this.ms.fs.body.dom)
  5675. n = this.view.findItemFromChild(n);
  5676. if(this.ms.appendOnly) {
  5677. insertAt = this.view.store.getCount();
  5678. } else {
  5679. insertAt = n == this.ms.fs.body.dom ? this.view.store.getCount() - 1 : this.view.indexOf(n);
  5680. if (pt == "below") {
  5681. insertAt++;
  5682. }
  5683. }
  5684. var dir = false;
  5685. // Validate if dragging within the same MultiSelect
  5686. if (data.sourceView == this.view) {
  5687. // If the first element to be inserted below is the target node, remove it
  5688. if (pt == "below") {
  5689. if (data.viewNodes[0] == n) {
  5690. data.viewNodes.shift();
  5691. }
  5692. } else { // If the last element to be inserted above is the target node, remove it
  5693. if (data.viewNodes[data.viewNodes.length - 1] == n) {
  5694. data.viewNodes.pop();
  5695. }
  5696. }
  5697. // Nothing to drop...
  5698. if (!data.viewNodes.length) {
  5699. return false;
  5700. }
  5701. // If we are moving DOWN, then because a store.remove() takes place first,
  5702. // the insertAt must be decremented.
  5703. if (insertAt > this.view.store.indexOf(data.records[0])) {
  5704. dir = 'down';
  5705. insertAt--;
  5706. }
  5707. }
  5708. for (var i = 0; i < data.records.length; i++) {
  5709. var r = data.records[i];
  5710. if (data.sourceView) {
  5711. data.sourceView.store.remove(r);
  5712. }
  5713. this.view.store.insert(dir == 'down' ? insertAt : insertAt++, r);
  5714. var si = this.view.store.sortInfo;
  5715. if(si){
  5716. this.view.store.sort(si.field, si.direction);
  5717. }
  5718. }
  5719. return true;
  5720. },
  5721. // private
  5722. removeDropIndicators : function(n){
  5723. if(n){
  5724. Ext.fly(n).removeClass([
  5725. "x-view-drag-insert-above",
  5726. "x-view-drag-insert-left",
  5727. "x-view-drag-insert-right",
  5728. "x-view-drag-insert-below"]);
  5729. this.lastInsertClass = "_noclass";
  5730. }
  5731. },
  5732. // private
  5733. setDroppable: function(ddGroup){
  5734. if (!ddGroup) return;
  5735. if (Ext.isArray(ddGroup)) {
  5736. Ext.each(ddGroup, this.setDroppable, this);
  5737. return;
  5738. }
  5739. this.addToGroup(ddGroup);
  5740. }
  5741. });
  5742. /* Fix for Opera, which does not seem to include the map function on Array's */
  5743. if (!Array.prototype.map) {
  5744. Array.prototype.map = function(fun){
  5745. var len = this.length;
  5746. if (typeof fun != 'function') {
  5747. throw new TypeError();
  5748. }
  5749. var res = new Array(len);
  5750. var thisp = arguments[1];
  5751. for (var i = 0; i < len; i++) {
  5752. if (i in this) {
  5753. res[i] = fun.call(thisp, this[i], i, this);
  5754. }
  5755. }
  5756. return res;
  5757. };
  5758. }
  5759. Ext.ns('Ext.ux.data');
  5760. /**
  5761. * @class Ext.ux.data.PagingMemoryProxy
  5762. * @extends Ext.data.MemoryProxy
  5763. * <p>Paging Memory Proxy, allows to use paging grid with in memory dataset</p>
  5764. */
  5765. Ext.ux.data.PagingMemoryProxy = Ext.extend(Ext.data.MemoryProxy, {
  5766. constructor : function(data){
  5767. Ext.ux.data.PagingMemoryProxy.superclass.constructor.call(this);
  5768. this.data = data;
  5769. },
  5770. doRequest : function(action, rs, params, reader, callback, scope, options){
  5771. params = params ||
  5772. {};
  5773. var result;
  5774. try {
  5775. result = reader.readRecords(this.data);
  5776. }
  5777. catch (e) {
  5778. this.fireEvent('loadexception', this, options, null, e);
  5779. callback.call(scope, null, options, false);
  5780. return;
  5781. }
  5782. // filtering
  5783. if (params.filter !== undefined) {
  5784. result.records = result.records.filter(function(el){
  5785. if (typeof(el) == 'object') {
  5786. var att = params.filterCol || 0;
  5787. return String(el.data[att]).match(params.filter) ? true : false;
  5788. }
  5789. else {
  5790. return String(el).match(params.filter) ? true : false;
  5791. }
  5792. });
  5793. result.totalRecords = result.records.length;
  5794. }
  5795. // sorting
  5796. if (params.sort !== undefined) {
  5797. // use integer as params.sort to specify column, since arrays are not named
  5798. // params.sort=0; would also match a array without columns
  5799. var dir = String(params.dir).toUpperCase() == 'DESC' ? -1 : 1;
  5800. var fn = function(v1, v2){
  5801. return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
  5802. };
  5803. result.records.sort(function(a, b){
  5804. var v = 0;
  5805. if (typeof(a) == 'object') {
  5806. v = fn(a.data[params.sort], b.data[params.sort]) * dir;
  5807. }
  5808. else {
  5809. v = fn(a, b) * dir;
  5810. }
  5811. if (v == 0) {
  5812. v = (a.index < b.index ? -1 : 1);
  5813. }
  5814. return v;
  5815. });
  5816. }
  5817. // paging (use undefined cause start can also be 0 (thus false))
  5818. if (params.start !== undefined && params.limit !== undefined) {
  5819. result.records = result.records.slice(params.start, params.start + params.limit);
  5820. }
  5821. callback.call(scope, result, options, true);
  5822. }
  5823. });
  5824. //backwards compat.
  5825. Ext.data.PagingMemoryProxy = Ext.ux.data.PagingMemoryProxy;
  5826. Ext.ux.PanelResizer = Ext.extend(Ext.util.Observable, {
  5827. minHeight: 0,
  5828. maxHeight:10000000,
  5829. constructor: function(config){
  5830. Ext.apply(this, config);
  5831. this.events = {};
  5832. Ext.ux.PanelResizer.superclass.constructor.call(this, config);
  5833. },
  5834. init : function(p){
  5835. this.panel = p;
  5836. if(this.panel.elements.indexOf('footer')==-1){
  5837. p.elements += ',footer';
  5838. }
  5839. p.on('render', this.onRender, this);
  5840. },
  5841. onRender : function(p){
  5842. this.handle = p.footer.createChild({cls:'x-panel-resize'});
  5843. this.tracker = new Ext.dd.DragTracker({
  5844. onStart: this.onDragStart.createDelegate(this),
  5845. onDrag: this.onDrag.createDelegate(this),
  5846. onEnd: this.onDragEnd.createDelegate(this),
  5847. tolerance: 3,
  5848. autoStart: 300
  5849. });
  5850. this.tracker.initEl(this.handle);
  5851. p.on('beforedestroy', this.tracker.destroy, this.tracker);
  5852. },
  5853. // private
  5854. onDragStart: function(e){
  5855. this.dragging = true;
  5856. this.startHeight = this.panel.el.getHeight();
  5857. this.fireEvent('dragstart', this, e);
  5858. },
  5859. // private
  5860. onDrag: function(e){
  5861. this.panel.setHeight((this.startHeight-this.tracker.getOffset()[1]).constrain(this.minHeight, this.maxHeight));
  5862. this.fireEvent('drag', this, e);
  5863. },
  5864. // private
  5865. onDragEnd: function(e){
  5866. this.dragging = false;
  5867. this.fireEvent('dragend', this, e);
  5868. }
  5869. });
  5870. Ext.preg('panelresizer', Ext.ux.PanelResizer);Ext.ux.Portal = Ext.extend(Ext.Panel, {
  5871. layout : 'column',
  5872. autoScroll : true,
  5873. cls : 'x-portal',
  5874. defaultType : 'portalcolumn',
  5875. initComponent : function(){
  5876. Ext.ux.Portal.superclass.initComponent.call(this);
  5877. this.addEvents({
  5878. validatedrop:true,
  5879. beforedragover:true,
  5880. dragover:true,
  5881. beforedrop:true,
  5882. drop:true
  5883. });
  5884. },
  5885. initEvents : function(){
  5886. Ext.ux.Portal.superclass.initEvents.call(this);
  5887. this.dd = new Ext.ux.Portal.DropZone(this, this.dropConfig);
  5888. },
  5889. beforeDestroy : function() {
  5890. if(this.dd){
  5891. this.dd.unreg();
  5892. }
  5893. Ext.ux.Portal.superclass.beforeDestroy.call(this);
  5894. }
  5895. });
  5896. Ext.reg('portal', Ext.ux.Portal);
  5897. Ext.ux.Portal.DropZone = Ext.extend(Ext.dd.DropTarget, {
  5898. constructor : function(portal, cfg){
  5899. this.portal = portal;
  5900. Ext.dd.ScrollManager.register(portal.body);
  5901. Ext.ux.Portal.DropZone.superclass.constructor.call(this, portal.bwrap.dom, cfg);
  5902. portal.body.ddScrollConfig = this.ddScrollConfig;
  5903. },
  5904. ddScrollConfig : {
  5905. vthresh: 50,
  5906. hthresh: -1,
  5907. animate: true,
  5908. increment: 200
  5909. },
  5910. createEvent : function(dd, e, data, col, c, pos){
  5911. return {
  5912. portal: this.portal,
  5913. panel: data.panel,
  5914. columnIndex: col,
  5915. column: c,
  5916. position: pos,
  5917. data: data,
  5918. source: dd,
  5919. rawEvent: e,
  5920. status: this.dropAllowed
  5921. };
  5922. },
  5923. notifyOver : function(dd, e, data){
  5924. var xy = e.getXY(), portal = this.portal, px = dd.proxy;
  5925. // case column widths
  5926. if(!this.grid){
  5927. this.grid = this.getGrid();
  5928. }
  5929. // handle case scroll where scrollbars appear during drag
  5930. var cw = portal.body.dom.clientWidth;
  5931. if(!this.lastCW){
  5932. this.lastCW = cw;
  5933. }else if(this.lastCW != cw){
  5934. this.lastCW = cw;
  5935. portal.doLayout();
  5936. this.grid = this.getGrid();
  5937. }
  5938. // determine column
  5939. var col = 0, xs = this.grid.columnX, cmatch = false;
  5940. for(var len = xs.length; col < len; col++){
  5941. if(xy[0] < (xs[col].x + xs[col].w)){
  5942. cmatch = true;
  5943. break;
  5944. }
  5945. }
  5946. // no match, fix last index
  5947. if(!cmatch){
  5948. col--;
  5949. }
  5950. // find insert position
  5951. var p, match = false, pos = 0,
  5952. c = portal.items.itemAt(col),
  5953. items = c.items.items, overSelf = false;
  5954. for(var len = items.length; pos < len; pos++){
  5955. p = items[pos];
  5956. var h = p.el.getHeight();
  5957. if(h === 0){
  5958. overSelf = true;
  5959. }
  5960. else if((p.el.getY()+(h/2)) > xy[1]){
  5961. match = true;
  5962. break;
  5963. }
  5964. }
  5965. pos = (match && p ? pos : c.items.getCount()) + (overSelf ? -1 : 0);
  5966. var overEvent = this.createEvent(dd, e, data, col, c, pos);
  5967. if(portal.fireEvent('validatedrop', overEvent) !== false &&
  5968. portal.fireEvent('beforedragover', overEvent) !== false){
  5969. // make sure proxy width is fluid
  5970. px.getProxy().setWidth('auto');
  5971. if(p){
  5972. px.moveProxy(p.el.dom.parentNode, match ? p.el.dom : null);
  5973. }else{
  5974. px.moveProxy(c.el.dom, null);
  5975. }
  5976. this.lastPos = {c: c, col: col, p: overSelf || (match && p) ? pos : false};
  5977. this.scrollPos = portal.body.getScroll();
  5978. portal.fireEvent('dragover', overEvent);
  5979. return overEvent.status;
  5980. }else{
  5981. return overEvent.status;
  5982. }
  5983. },
  5984. notifyOut : function(){
  5985. delete this.grid;
  5986. },
  5987. notifyDrop : function(dd, e, data){
  5988. delete this.grid;
  5989. if(!this.lastPos){
  5990. return;
  5991. }
  5992. var c = this.lastPos.c,
  5993. col = this.lastPos.col,
  5994. pos = this.lastPos.p,
  5995. panel = dd.panel,
  5996. dropEvent = this.createEvent(dd, e, data, col, c,
  5997. pos !== false ? pos : c.items.getCount());
  5998. if(this.portal.fireEvent('validatedrop', dropEvent) !== false &&
  5999. this.portal.fireEvent('beforedrop', dropEvent) !== false){
  6000. dd.proxy.getProxy().remove();
  6001. panel.el.dom.parentNode.removeChild(dd.panel.el.dom);
  6002. if(pos !== false){
  6003. c.insert(pos, panel);
  6004. }else{
  6005. c.add(panel);
  6006. }
  6007. c.doLayout();
  6008. this.portal.fireEvent('drop', dropEvent);
  6009. // scroll position is lost on drop, fix it
  6010. var st = this.scrollPos.top;
  6011. if(st){
  6012. var d = this.portal.body.dom;
  6013. setTimeout(function(){
  6014. d.scrollTop = st;
  6015. }, 10);
  6016. }
  6017. }
  6018. delete this.lastPos;
  6019. },
  6020. // internal cache of body and column coords
  6021. getGrid : function(){
  6022. var box = this.portal.bwrap.getBox();
  6023. box.columnX = [];
  6024. this.portal.items.each(function(c){
  6025. box.columnX.push({x: c.el.getX(), w: c.el.getWidth()});
  6026. });
  6027. return box;
  6028. },
  6029. // unregister the dropzone from ScrollManager
  6030. unreg: function() {
  6031. Ext.dd.ScrollManager.unregister(this.portal.body);
  6032. Ext.ux.Portal.DropZone.superclass.unreg.call(this);
  6033. }
  6034. });
  6035. Ext.ux.PortalColumn = Ext.extend(Ext.Container, {
  6036. layout : 'anchor',
  6037. //autoEl : 'div',//already defined by Ext.Component
  6038. defaultType : 'portlet',
  6039. cls : 'x-portal-column'
  6040. });
  6041. Ext.reg('portalcolumn', Ext.ux.PortalColumn);
  6042. Ext.ux.Portlet = Ext.extend(Ext.Panel, {
  6043. anchor : '100%',
  6044. frame : true,
  6045. collapsible : true,
  6046. draggable : true,
  6047. cls : 'x-portlet'
  6048. });
  6049. Ext.reg('portlet', Ext.ux.Portlet);
  6050. /**
  6051. * @class Ext.ux.ProgressBarPager
  6052. * @extends Object
  6053. * Plugin (ptype = 'tabclosemenu') for displaying a progressbar inside of a paging toolbar instead of plain text
  6054. *
  6055. * @ptype progressbarpager
  6056. * @constructor
  6057. * Create a new ItemSelector
  6058. * @param {Object} config Configuration options
  6059. * @xtype itemselector
  6060. */
  6061. Ext.ux.ProgressBarPager = Ext.extend(Object, {
  6062. /**
  6063. * @cfg {Integer} progBarWidth
  6064. * <p>The default progress bar width. Default is 225.</p>
  6065. */
  6066. progBarWidth : 225,
  6067. /**
  6068. * @cfg {String} defaultText
  6069. * <p>The text to display while the store is loading. Default is 'Loading...'</p>
  6070. */
  6071. defaultText : 'Loading...',
  6072. /**
  6073. * @cfg {Object} defaultAnimCfg
  6074. * <p>A {@link Ext.Fx Ext.Fx} configuration object. Default is { duration : 1, easing : 'bounceOut' }.</p>
  6075. */
  6076. defaultAnimCfg : {
  6077. duration : 1,
  6078. easing : 'bounceOut'
  6079. },
  6080. constructor : function(config) {
  6081. if (config) {
  6082. Ext.apply(this, config);
  6083. }
  6084. },
  6085. //public
  6086. init : function (parent) {
  6087. if(parent.displayInfo){
  6088. this.parent = parent;
  6089. var ind = parent.items.indexOf(parent.displayItem);
  6090. parent.remove(parent.displayItem, true);
  6091. this.progressBar = new Ext.ProgressBar({
  6092. text : this.defaultText,
  6093. width : this.progBarWidth,
  6094. animate : this.defaultAnimCfg
  6095. });
  6096. parent.displayItem = this.progressBar;
  6097. parent.add(parent.displayItem);
  6098. parent.doLayout();
  6099. Ext.apply(parent, this.parentOverrides);
  6100. this.progressBar.on('render', function(pb) {
  6101. pb.mon(pb.getEl().applyStyles('cursor:pointer'), 'click', this.handleProgressBarClick, this);
  6102. }, this, {single: true});
  6103. }
  6104. },
  6105. // private
  6106. // This method handles the click for the progress bar
  6107. handleProgressBarClick : function(e){
  6108. var parent = this.parent,
  6109. displayItem = parent.displayItem,
  6110. box = this.progressBar.getBox(),
  6111. xy = e.getXY(),
  6112. position = xy[0]-box.x,
  6113. pages = Math.ceil(parent.store.getTotalCount()/parent.pageSize),
  6114. newpage = Math.ceil(position/(displayItem.width/pages));
  6115. parent.changePage(newpage);
  6116. },
  6117. // private, overriddes
  6118. parentOverrides : {
  6119. // private
  6120. // This method updates the information via the progress bar.
  6121. updateInfo : function(){
  6122. if(this.displayItem){
  6123. var count = this.store.getCount(),
  6124. pgData = this.getPageData(),
  6125. pageNum = this.readPage(pgData),
  6126. msg = count == 0 ?
  6127. this.emptyMsg :
  6128. String.format(
  6129. this.displayMsg,
  6130. this.cursor+1, this.cursor+count, this.store.getTotalCount()
  6131. );
  6132. pageNum = pgData.activePage; ;
  6133. var pct = pageNum / pgData.pages;
  6134. this.displayItem.updateProgress(pct, msg, this.animate || this.defaultAnimConfig);
  6135. }
  6136. }
  6137. }
  6138. });
  6139. Ext.preg('progressbarpager', Ext.ux.ProgressBarPager);
  6140. Ext.ns('Ext.ux.grid');
  6141. /**
  6142. * @class Ext.ux.grid.RowEditor
  6143. * @extends Ext.Panel
  6144. * Plugin (ptype = 'roweditor') that adds the ability to rapidly edit full rows in a grid.
  6145. * A validation mode may be enabled which uses AnchorTips to notify the user of all
  6146. * validation errors at once.
  6147. *
  6148. * @ptype roweditor
  6149. */
  6150. Ext.ux.grid.RowEditor = Ext.extend(Ext.Panel, {
  6151. floating: true,
  6152. shadow: false,
  6153. layout: 'hbox',
  6154. cls: 'x-small-editor',
  6155. buttonAlign: 'center',
  6156. baseCls: 'x-row-editor',
  6157. elements: 'header,footer,body',
  6158. frameWidth: 5,
  6159. buttonPad: 3,
  6160. clicksToEdit: 'auto',
  6161. monitorValid: true,
  6162. focusDelay: 250,
  6163. errorSummary: true,
  6164. saveText: 'Save',
  6165. cancelText: 'Cancel',
  6166. commitChangesText: 'You need to commit or cancel your changes',
  6167. errorText: 'Errors',
  6168. defaults: {
  6169. normalWidth: true
  6170. },
  6171. initComponent: function(){
  6172. Ext.ux.grid.RowEditor.superclass.initComponent.call(this);
  6173. this.addEvents(
  6174. /**
  6175. * @event beforeedit
  6176. * Fired before the row editor is activated.
  6177. * If the listener returns <tt>false</tt> the editor will not be activated.
  6178. * @param {Ext.ux.grid.RowEditor} roweditor This object
  6179. * @param {Number} rowIndex The rowIndex of the row just edited
  6180. */
  6181. 'beforeedit',
  6182. /**
  6183. * @event canceledit
  6184. * Fired when the editor is cancelled.
  6185. * @param {Ext.ux.grid.RowEditor} roweditor This object
  6186. * @param {Boolean} forced True if the cancel button is pressed, false is the editor was invalid.
  6187. */
  6188. 'canceledit',
  6189. /**
  6190. * @event validateedit
  6191. * Fired after a row is edited and passes validation.
  6192. * If the listener returns <tt>false</tt> changes to the record will not be set.
  6193. * @param {Ext.ux.grid.RowEditor} roweditor This object
  6194. * @param {Object} changes Object with changes made to the record.
  6195. * @param {Ext.data.Record} r The Record that was edited.
  6196. * @param {Number} rowIndex The rowIndex of the row just edited
  6197. */
  6198. 'validateedit',
  6199. /**
  6200. * @event afteredit
  6201. * Fired after a row is edited and passes validation. This event is fired
  6202. * after the store's update event is fired with this edit.
  6203. * @param {Ext.ux.grid.RowEditor} roweditor This object
  6204. * @param {Object} changes Object with changes made to the record.
  6205. * @param {Ext.data.Record} r The Record that was edited.
  6206. * @param {Number} rowIndex The rowIndex of the row just edited
  6207. */
  6208. 'afteredit'
  6209. );
  6210. },
  6211. init: function(grid){
  6212. this.grid = grid;
  6213. this.ownerCt = grid;
  6214. if(this.clicksToEdit === 2){
  6215. grid.on('rowdblclick', this.onRowDblClick, this);
  6216. }else{
  6217. grid.on('rowclick', this.onRowClick, this);
  6218. if(Ext.isIE){
  6219. grid.on('rowdblclick', this.onRowDblClick, this);
  6220. }
  6221. }
  6222. // stopEditing without saving when a record is removed from Store.
  6223. grid.getStore().on('remove', function() {
  6224. this.stopEditing(false);
  6225. },this);
  6226. grid.on({
  6227. scope: this,
  6228. keydown: this.onGridKey,
  6229. columnresize: this.verifyLayout,
  6230. columnmove: this.refreshFields,
  6231. reconfigure: this.refreshFields,
  6232. beforedestroy : this.beforedestroy,
  6233. destroy : this.destroy,
  6234. bodyscroll: {
  6235. buffer: 250,
  6236. fn: this.positionButtons
  6237. }
  6238. });
  6239. grid.getColumnModel().on('hiddenchange', this.verifyLayout, this, {delay:1});
  6240. grid.getView().on('refresh', this.stopEditing.createDelegate(this, []));
  6241. },
  6242. beforedestroy: function() {
  6243. this.stopMonitoring();
  6244. this.grid.getStore().un('remove', this.onStoreRemove, this);
  6245. this.stopEditing(false);
  6246. Ext.destroy(this.btns, this.tooltip);
  6247. },
  6248. refreshFields: function(){
  6249. this.initFields();
  6250. this.verifyLayout();
  6251. },
  6252. isDirty: function(){
  6253. var dirty;
  6254. this.items.each(function(f){
  6255. if(String(this.values[f.id]) !== String(f.getValue())){
  6256. dirty = true;
  6257. return false;
  6258. }
  6259. }, this);
  6260. return dirty;
  6261. },
  6262. startEditing: function(rowIndex, doFocus){
  6263. if(this.editing && this.isDirty()){
  6264. this.showTooltip(this.commitChangesText);
  6265. return;
  6266. }
  6267. if(Ext.isObject(rowIndex)){
  6268. rowIndex = this.grid.getStore().indexOf(rowIndex);
  6269. }
  6270. if(this.fireEvent('beforeedit', this, rowIndex) !== false){
  6271. this.editing = true;
  6272. var g = this.grid, view = g.getView(),
  6273. row = view.getRow(rowIndex),
  6274. record = g.store.getAt(rowIndex);
  6275. this.record = record;
  6276. this.rowIndex = rowIndex;
  6277. this.values = {};
  6278. if(!this.rendered){
  6279. this.render(view.getEditorParent());
  6280. }
  6281. var w = Ext.fly(row).getWidth();
  6282. this.setSize(w);
  6283. if(!this.initialized){
  6284. this.initFields();
  6285. }
  6286. var cm = g.getColumnModel(), fields = this.items.items, f, val;
  6287. for(var i = 0, len = cm.getColumnCount(); i < len; i++){
  6288. val = this.preEditValue(record, cm.getDataIndex(i));
  6289. f = fields[i];
  6290. f.setValue(val);
  6291. this.values[f.id] = Ext.isEmpty(val) ? '' : val;
  6292. }
  6293. this.verifyLayout(true);
  6294. if(!this.isVisible()){
  6295. this.setPagePosition(Ext.fly(row).getXY());
  6296. } else{
  6297. this.el.setXY(Ext.fly(row).getXY(), {duration:0.15});
  6298. }
  6299. if(!this.isVisible()){
  6300. this.show().doLayout();
  6301. }
  6302. if(doFocus !== false){
  6303. this.doFocus.defer(this.focusDelay, this);
  6304. }
  6305. }
  6306. },
  6307. stopEditing : function(saveChanges){
  6308. this.editing = false;
  6309. if(!this.isVisible()){
  6310. return;
  6311. }
  6312. if(saveChanges === false || !this.isValid()){
  6313. this.hide();
  6314. this.fireEvent('canceledit', this, saveChanges === false);
  6315. return;
  6316. }
  6317. var changes = {},
  6318. r = this.record,
  6319. hasChange = false,
  6320. cm = this.grid.colModel,
  6321. fields = this.items.items;
  6322. for(var i = 0, len = cm.getColumnCount(); i < len; i++){
  6323. if(!cm.isHidden(i)){
  6324. var dindex = cm.getDataIndex(i);
  6325. if(!Ext.isEmpty(dindex)){
  6326. var oldValue = r.data[dindex],
  6327. value = this.postEditValue(fields[i].getValue(), oldValue, r, dindex);
  6328. if(String(oldValue) !== String(value)){
  6329. changes[dindex] = value;
  6330. hasChange = true;
  6331. }
  6332. }
  6333. }
  6334. }
  6335. if(hasChange && this.fireEvent('validateedit', this, changes, r, this.rowIndex) !== false){
  6336. r.beginEdit();
  6337. Ext.iterate(changes, function(name, value){
  6338. r.set(name, value);
  6339. });
  6340. r.endEdit();
  6341. this.fireEvent('afteredit', this, changes, r, this.rowIndex);
  6342. }
  6343. this.hide();
  6344. },
  6345. verifyLayout: function(force){
  6346. if(this.el && (this.isVisible() || force === true)){
  6347. var row = this.grid.getView().getRow(this.rowIndex);
  6348. this.setSize(Ext.fly(row).getWidth(), Ext.isIE ? Ext.fly(row).getHeight() + 9 : undefined);
  6349. var cm = this.grid.colModel, fields = this.items.items;
  6350. for(var i = 0, len = cm.getColumnCount(); i < len; i++){
  6351. if(!cm.isHidden(i)){
  6352. var adjust = 0;
  6353. if(i === (len - 1)){
  6354. adjust += 3; // outer padding
  6355. } else{
  6356. adjust += 1;
  6357. }
  6358. fields[i].show();
  6359. fields[i].setWidth(cm.getColumnWidth(i) - adjust);
  6360. } else{
  6361. fields[i].hide();
  6362. }
  6363. }
  6364. this.doLayout();
  6365. this.positionButtons();
  6366. }
  6367. },
  6368. slideHide : function(){
  6369. this.hide();
  6370. },
  6371. initFields: function(){
  6372. var cm = this.grid.getColumnModel(), pm = Ext.layout.ContainerLayout.prototype.parseMargins;
  6373. this.removeAll(false);
  6374. for(var i = 0, len = cm.getColumnCount(); i < len; i++){
  6375. var c = cm.getColumnAt(i),
  6376. ed = c.getEditor();
  6377. if(!ed){
  6378. ed = c.displayEditor || new Ext.form.DisplayField();
  6379. }
  6380. if(i == 0){
  6381. ed.margins = pm('0 1 2 1');
  6382. } else if(i == len - 1){
  6383. ed.margins = pm('0 0 2 1');
  6384. } else{
  6385. if (Ext.isIE) {
  6386. ed.margins = pm('0 0 2 0');
  6387. }
  6388. else {
  6389. ed.margins = pm('0 1 2 0');
  6390. }
  6391. }
  6392. ed.setWidth(cm.getColumnWidth(i));
  6393. ed.column = c;
  6394. if(ed.ownerCt !== this){
  6395. ed.on('focus', this.ensureVisible, this);
  6396. ed.on('specialkey', this.onKey, this);
  6397. }
  6398. this.insert(i, ed);
  6399. }
  6400. this.initialized = true;
  6401. },
  6402. onKey: function(f, e){
  6403. if(e.getKey() === e.ENTER){
  6404. this.stopEditing(true);
  6405. e.stopPropagation();
  6406. }
  6407. },
  6408. onGridKey: function(e){
  6409. if(e.getKey() === e.ENTER && !this.isVisible()){
  6410. var r = this.grid.getSelectionModel().getSelected();
  6411. if(r){
  6412. var index = this.grid.store.indexOf(r);
  6413. this.startEditing(index);
  6414. e.stopPropagation();
  6415. }
  6416. }
  6417. },
  6418. ensureVisible: function(editor){
  6419. if(this.isVisible()){
  6420. this.grid.getView().ensureVisible(this.rowIndex, this.grid.colModel.getIndexById(editor.column.id), true);
  6421. }
  6422. },
  6423. onRowClick: function(g, rowIndex, e){
  6424. if(this.clicksToEdit == 'auto'){
  6425. var li = this.lastClickIndex;
  6426. this.lastClickIndex = rowIndex;
  6427. if(li != rowIndex && !this.isVisible()){
  6428. return;
  6429. }
  6430. }
  6431. this.startEditing(rowIndex, false);
  6432. this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
  6433. },
  6434. onRowDblClick: function(g, rowIndex, e){
  6435. this.startEditing(rowIndex, false);
  6436. this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
  6437. },
  6438. onRender: function(){
  6439. Ext.ux.grid.RowEditor.superclass.onRender.apply(this, arguments);
  6440. this.el.swallowEvent(['keydown', 'keyup', 'keypress']);
  6441. this.btns = new Ext.Panel({
  6442. baseCls: 'x-plain',
  6443. cls: 'x-btns',
  6444. elements:'body',
  6445. layout: 'table',
  6446. width: (this.minButtonWidth * 2) + (this.frameWidth * 2) + (this.buttonPad * 4), // width must be specified for IE
  6447. items: [{
  6448. ref: 'saveBtn',
  6449. itemId: 'saveBtn',
  6450. xtype: 'button',
  6451. text: this.saveText,
  6452. width: this.minButtonWidth,
  6453. handler: this.stopEditing.createDelegate(this, [true])
  6454. }, {
  6455. xtype: 'button',
  6456. text: this.cancelText,
  6457. width: this.minButtonWidth,
  6458. handler: this.stopEditing.createDelegate(this, [false])
  6459. }]
  6460. });
  6461. this.btns.render(this.bwrap);
  6462. },
  6463. afterRender: function(){
  6464. Ext.ux.grid.RowEditor.superclass.afterRender.apply(this, arguments);
  6465. this.positionButtons();
  6466. if(this.monitorValid){
  6467. this.startMonitoring();
  6468. }
  6469. },
  6470. onShow: function(){
  6471. if(this.monitorValid){
  6472. this.startMonitoring();
  6473. }
  6474. Ext.ux.grid.RowEditor.superclass.onShow.apply(this, arguments);
  6475. },
  6476. onHide: function(){
  6477. Ext.ux.grid.RowEditor.superclass.onHide.apply(this, arguments);
  6478. this.stopMonitoring();
  6479. this.grid.getView().focusRow(this.rowIndex);
  6480. },
  6481. positionButtons: function(){
  6482. if(this.btns){
  6483. var g = this.grid,
  6484. h = this.el.dom.clientHeight,
  6485. view = g.getView(),
  6486. scroll = view.scroller.dom.scrollLeft,
  6487. bw = this.btns.getWidth(),
  6488. width = Math.min(g.getWidth(), g.getColumnModel().getTotalWidth());
  6489. this.btns.el.shift({left: (width/2)-(bw/2)+scroll, top: h - 2, stopFx: true, duration:0.2});
  6490. }
  6491. },
  6492. // private
  6493. preEditValue : function(r, field){
  6494. var value = r.data[field];
  6495. return this.autoEncode && typeof value === 'string' ? Ext.util.Format.htmlDecode(value) : value;
  6496. },
  6497. // private
  6498. postEditValue : function(value, originalValue, r, field){
  6499. return this.autoEncode && typeof value == 'string' ? Ext.util.Format.htmlEncode(value) : value;
  6500. },
  6501. doFocus: function(pt){
  6502. if(this.isVisible()){
  6503. var index = 0,
  6504. cm = this.grid.getColumnModel(),
  6505. c;
  6506. if(pt){
  6507. index = this.getTargetColumnIndex(pt);
  6508. }
  6509. for(var i = index||0, len = cm.getColumnCount(); i < len; i++){
  6510. c = cm.getColumnAt(i);
  6511. if(!c.hidden && c.getEditor()){
  6512. c.getEditor().focus();
  6513. break;
  6514. }
  6515. }
  6516. }
  6517. },
  6518. getTargetColumnIndex: function(pt){
  6519. var grid = this.grid,
  6520. v = grid.view,
  6521. x = pt.left,
  6522. cms = grid.colModel.config,
  6523. i = 0,
  6524. match = false;
  6525. for(var len = cms.length, c; c = cms[i]; i++){
  6526. if(!c.hidden){
  6527. if(Ext.fly(v.getHeaderCell(i)).getRegion().right >= x){
  6528. match = i;
  6529. break;
  6530. }
  6531. }
  6532. }
  6533. return match;
  6534. },
  6535. startMonitoring : function(){
  6536. if(!this.bound && this.monitorValid){
  6537. this.bound = true;
  6538. Ext.TaskMgr.start({
  6539. run : this.bindHandler,
  6540. interval : this.monitorPoll || 200,
  6541. scope: this
  6542. });
  6543. }
  6544. },
  6545. stopMonitoring : function(){
  6546. this.bound = false;
  6547. if(this.tooltip){
  6548. this.tooltip.hide();
  6549. }
  6550. },
  6551. isValid: function(){
  6552. var valid = true;
  6553. this.items.each(function(f){
  6554. if(!f.isValid(true)){
  6555. valid = false;
  6556. return false;
  6557. }
  6558. });
  6559. return valid;
  6560. },
  6561. // private
  6562. bindHandler : function(){
  6563. if(!this.bound){
  6564. return false; // stops binding
  6565. }
  6566. var valid = this.isValid();
  6567. if(!valid && this.errorSummary){
  6568. this.showTooltip(this.getErrorText().join(''));
  6569. }
  6570. this.btns.saveBtn.setDisabled(!valid);
  6571. this.fireEvent('validation', this, valid);
  6572. },
  6573. lastVisibleColumn : function() {
  6574. var i = this.items.getCount() - 1,
  6575. c;
  6576. for(; i >= 0; i--) {
  6577. c = this.items.items[i];
  6578. if (!c.hidden) {
  6579. return c;
  6580. }
  6581. }
  6582. },
  6583. showTooltip: function(msg){
  6584. var t = this.tooltip;
  6585. if(!t){
  6586. t = this.tooltip = new Ext.ToolTip({
  6587. maxWidth: 600,
  6588. cls: 'errorTip',
  6589. width: 300,
  6590. title: this.errorText,
  6591. autoHide: false,
  6592. anchor: 'left',
  6593. anchorToTarget: true,
  6594. mouseOffset: [40,0]
  6595. });
  6596. }
  6597. var v = this.grid.getView(),
  6598. top = parseInt(this.el.dom.style.top, 10),
  6599. scroll = v.scroller.dom.scrollTop,
  6600. h = this.el.getHeight();
  6601. if(top + h >= scroll){
  6602. t.initTarget(this.lastVisibleColumn().getEl());
  6603. if(!t.rendered){
  6604. t.show();
  6605. t.hide();
  6606. }
  6607. t.body.update(msg);
  6608. t.doAutoWidth(20);
  6609. t.show();
  6610. }else if(t.rendered){
  6611. t.hide();
  6612. }
  6613. },
  6614. getErrorText: function(){
  6615. var data = ['<ul>'];
  6616. this.items.each(function(f){
  6617. if(!f.isValid(true)){
  6618. data.push('<li>', f.getActiveError(), '</li>');
  6619. }
  6620. });
  6621. data.push('</ul>');
  6622. return data;
  6623. }
  6624. });
  6625. Ext.preg('roweditor', Ext.ux.grid.RowEditor);
  6626. Ext.ns('Ext.ux.grid');
  6627. /**
  6628. * @class Ext.ux.grid.RowExpander
  6629. * @extends Ext.util.Observable
  6630. * Plugin (ptype = 'rowexpander') that adds the ability to have a Column in a grid which enables
  6631. * a second row body which expands/contracts. The expand/contract behavior is configurable to react
  6632. * on clicking of the column, double click of the row, and/or hitting enter while a row is selected.
  6633. *
  6634. * @ptype rowexpander
  6635. */
  6636. Ext.ux.grid.RowExpander = Ext.extend(Ext.util.Observable, {
  6637. /**
  6638. * @cfg {Boolean} expandOnEnter
  6639. * <tt>true</tt> to toggle selected row(s) between expanded/collapsed when the enter
  6640. * key is pressed (defaults to <tt>true</tt>).
  6641. */
  6642. expandOnEnter : true,
  6643. /**
  6644. * @cfg {Boolean} expandOnDblClick
  6645. * <tt>true</tt> to toggle a row between expanded/collapsed when double clicked
  6646. * (defaults to <tt>true</tt>).
  6647. */
  6648. expandOnDblClick : true,
  6649. header : '',
  6650. width : 20,
  6651. sortable : false,
  6652. fixed : true,
  6653. hideable: false,
  6654. menuDisabled : true,
  6655. dataIndex : '',
  6656. id : 'expander',
  6657. lazyRender : true,
  6658. enableCaching : true,
  6659. constructor: function(config){
  6660. Ext.apply(this, config);
  6661. this.addEvents({
  6662. /**
  6663. * @event beforeexpand
  6664. * Fires before the row expands. Have the listener return false to prevent the row from expanding.
  6665. * @param {Object} this RowExpander object.
  6666. * @param {Object} Ext.data.Record Record for the selected row.
  6667. * @param {Object} body body element for the secondary row.
  6668. * @param {Number} rowIndex The current row index.
  6669. */
  6670. beforeexpand: true,
  6671. /**
  6672. * @event expand
  6673. * Fires after the row expands.
  6674. * @param {Object} this RowExpander object.
  6675. * @param {Object} Ext.data.Record Record for the selected row.
  6676. * @param {Object} body body element for the secondary row.
  6677. * @param {Number} rowIndex The current row index.
  6678. */
  6679. expand: true,
  6680. /**
  6681. * @event beforecollapse
  6682. * Fires before the row collapses. Have the listener return false to prevent the row from collapsing.
  6683. * @param {Object} this RowExpander object.
  6684. * @param {Object} Ext.data.Record Record for the selected row.
  6685. * @param {Object} body body element for the secondary row.
  6686. * @param {Number} rowIndex The current row index.
  6687. */
  6688. beforecollapse: true,
  6689. /**
  6690. * @event collapse
  6691. * Fires after the row collapses.
  6692. * @param {Object} this RowExpander object.
  6693. * @param {Object} Ext.data.Record Record for the selected row.
  6694. * @param {Object} body body element for the secondary row.
  6695. * @param {Number} rowIndex The current row index.
  6696. */
  6697. collapse: true
  6698. });
  6699. Ext.ux.grid.RowExpander.superclass.constructor.call(this);
  6700. if(this.tpl){
  6701. if(typeof this.tpl == 'string'){
  6702. this.tpl = new Ext.Template(this.tpl);
  6703. }
  6704. this.tpl.compile();
  6705. }
  6706. this.state = {};
  6707. this.bodyContent = {};
  6708. },
  6709. getRowClass : function(record, rowIndex, p, ds){
  6710. p.cols = p.cols-1;
  6711. var content = this.bodyContent[record.id];
  6712. if(!content && !this.lazyRender){
  6713. content = this.getBodyContent(record, rowIndex);
  6714. }
  6715. if(content){
  6716. p.body = content;
  6717. }
  6718. return this.state[record.id] ? 'x-grid3-row-expanded' : 'x-grid3-row-collapsed';
  6719. },
  6720. init : function(grid){
  6721. this.grid = grid;
  6722. var view = grid.getView();
  6723. view.getRowClass = this.getRowClass.createDelegate(this);
  6724. view.enableRowBody = true;
  6725. grid.on('render', this.onRender, this);
  6726. grid.on('destroy', this.onDestroy, this);
  6727. },
  6728. // @private
  6729. onRender: function() {
  6730. var grid = this.grid;
  6731. var mainBody = grid.getView().mainBody;
  6732. mainBody.on('mousedown', this.onMouseDown, this, {delegate: '.x-grid3-row-expander'});
  6733. if (this.expandOnEnter) {
  6734. this.keyNav = new Ext.KeyNav(this.grid.getGridEl(), {
  6735. 'enter' : this.onEnter,
  6736. scope: this
  6737. });
  6738. }
  6739. if (this.expandOnDblClick) {
  6740. grid.on('rowdblclick', this.onRowDblClick, this);
  6741. }
  6742. },
  6743. // @private
  6744. onDestroy: function() {
  6745. if(this.keyNav){
  6746. this.keyNav.disable();
  6747. delete this.keyNav;
  6748. }
  6749. /*
  6750. * A majority of the time, the plugin will be destroyed along with the grid,
  6751. * which means the mainBody won't be available. On the off chance that the plugin
  6752. * isn't destroyed with the grid, take care of removing the listener.
  6753. */
  6754. var mainBody = this.grid.getView().mainBody;
  6755. if(mainBody){
  6756. mainBody.un('mousedown', this.onMouseDown, this);
  6757. }
  6758. },
  6759. // @private
  6760. onRowDblClick: function(grid, rowIdx, e) {
  6761. this.toggleRow(rowIdx);
  6762. },
  6763. onEnter: function(e) {
  6764. var g = this.grid;
  6765. var sm = g.getSelectionModel();
  6766. var sels = sm.getSelections();
  6767. for (var i = 0, len = sels.length; i < len; i++) {
  6768. var rowIdx = g.getStore().indexOf(sels[i]);
  6769. this.toggleRow(rowIdx);
  6770. }
  6771. },
  6772. getBodyContent : function(record, index){
  6773. if(!this.enableCaching){
  6774. return this.tpl.apply(record.data);
  6775. }
  6776. var content = this.bodyContent[record.id];
  6777. if(!content){
  6778. content = this.tpl.apply(record.data);
  6779. this.bodyContent[record.id] = content;
  6780. }
  6781. return content;
  6782. },
  6783. onMouseDown : function(e, t){
  6784. e.stopEvent();
  6785. var row = e.getTarget('.x-grid3-row');
  6786. this.toggleRow(row);
  6787. },
  6788. renderer : function(v, p, record){
  6789. p.cellAttr = 'rowspan="2"';
  6790. return '<div class="x-grid3-row-expander">&#160;</div>';
  6791. },
  6792. beforeExpand : function(record, body, rowIndex){
  6793. if(this.fireEvent('beforeexpand', this, record, body, rowIndex) !== false){
  6794. if(this.tpl && this.lazyRender){
  6795. body.innerHTML = this.getBodyContent(record, rowIndex);
  6796. }
  6797. return true;
  6798. }else{
  6799. return false;
  6800. }
  6801. },
  6802. toggleRow : function(row){
  6803. if(typeof row == 'number'){
  6804. row = this.grid.view.getRow(row);
  6805. }
  6806. this[Ext.fly(row).hasClass('x-grid3-row-collapsed') ? 'expandRow' : 'collapseRow'](row);
  6807. },
  6808. expandRow : function(row){
  6809. if(typeof row == 'number'){
  6810. row = this.grid.view.getRow(row);
  6811. }
  6812. var record = this.grid.store.getAt(row.rowIndex);
  6813. var body = Ext.DomQuery.selectNode('tr:nth(2) div.x-grid3-row-body', row);
  6814. if(this.beforeExpand(record, body, row.rowIndex)){
  6815. this.state[record.id] = true;
  6816. Ext.fly(row).replaceClass('x-grid3-row-collapsed', 'x-grid3-row-expanded');
  6817. this.fireEvent('expand', this, record, body, row.rowIndex);
  6818. }
  6819. },
  6820. collapseRow : function(row){
  6821. if(typeof row == 'number'){
  6822. row = this.grid.view.getRow(row);
  6823. }
  6824. var record = this.grid.store.getAt(row.rowIndex);
  6825. var body = Ext.fly(row).child('tr:nth(1) div.x-grid3-row-body', true);
  6826. if(this.fireEvent('beforecollapse', this, record, body, row.rowIndex) !== false){
  6827. this.state[record.id] = false;
  6828. Ext.fly(row).replaceClass('x-grid3-row-expanded', 'x-grid3-row-collapsed');
  6829. this.fireEvent('collapse', this, record, body, row.rowIndex);
  6830. }
  6831. }
  6832. });
  6833. Ext.preg('rowexpander', Ext.ux.grid.RowExpander);
  6834. //backwards compat
  6835. Ext.grid.RowExpander = Ext.ux.grid.RowExpander;// We are adding these custom layouts to a namespace that does not
  6836. // exist by default in Ext, so we have to add the namespace first:
  6837. Ext.ns('Ext.ux.layout');
  6838. /**
  6839. * @class Ext.ux.layout.RowLayout
  6840. * @extends Ext.layout.ContainerLayout
  6841. * <p>This is the layout style of choice for creating structural layouts in a multi-row format where the height of
  6842. * each row can be specified as a percentage or fixed height. Row widths can also be fixed, percentage or auto.
  6843. * This class is intended to be extended or created via the layout:'ux.row' {@link Ext.Container#layout} config,
  6844. * and should generally not need to be created directly via the new keyword.</p>
  6845. * <p>RowLayout does not have any direct config options (other than inherited ones), but it does support a
  6846. * specific config property of <b><tt>rowHeight</tt></b> that can be included in the config of any panel added to it. The
  6847. * layout will use the rowHeight (if present) or height of each panel during layout to determine how to size each panel.
  6848. * If height or rowHeight is not specified for a given panel, its height will default to the panel's height (or auto).</p>
  6849. * <p>The height property is always evaluated as pixels, and must be a number greater than or equal to 1.
  6850. * The rowHeight property is always evaluated as a percentage, and must be a decimal value greater than 0 and
  6851. * less than 1 (e.g., .25).</p>
  6852. * <p>The basic rules for specifying row heights are pretty simple. The logic makes two passes through the
  6853. * set of contained panels. During the first layout pass, all panels that either have a fixed height or none
  6854. * specified (auto) are skipped, but their heights are subtracted from the overall container height. During the second
  6855. * pass, all panels with rowHeights are assigned pixel heights in proportion to their percentages based on
  6856. * the total <b>remaining</b> container height. In other words, percentage height panels are designed to fill the space
  6857. * left over by all the fixed-height and/or auto-height panels. Because of this, while you can specify any number of rows
  6858. * with different percentages, the rowHeights must always add up to 1 (or 100%) when added together, otherwise your
  6859. * layout may not render as expected. Example usage:</p>
  6860. * <pre><code>
  6861. // All rows are percentages -- they must add up to 1
  6862. var p = new Ext.Panel({
  6863. title: 'Row Layout - Percentage Only',
  6864. layout:'ux.row',
  6865. items: [{
  6866. title: 'Row 1',
  6867. rowHeight: .25
  6868. },{
  6869. title: 'Row 2',
  6870. rowHeight: .6
  6871. },{
  6872. title: 'Row 3',
  6873. rowHeight: .15
  6874. }]
  6875. });
  6876. // Mix of height and rowHeight -- all rowHeight values must add
  6877. // up to 1. The first row will take up exactly 120px, and the last two
  6878. // rows will fill the remaining container height.
  6879. var p = new Ext.Panel({
  6880. title: 'Row Layout - Mixed',
  6881. layout:'ux.row',
  6882. items: [{
  6883. title: 'Row 1',
  6884. height: 120,
  6885. // standard panel widths are still supported too:
  6886. width: '50%' // or 200
  6887. },{
  6888. title: 'Row 2',
  6889. rowHeight: .8,
  6890. width: 300
  6891. },{
  6892. title: 'Row 3',
  6893. rowHeight: .2
  6894. }]
  6895. });
  6896. </code></pre>
  6897. */
  6898. Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, {
  6899. // private
  6900. monitorResize:true,
  6901. type: 'row',
  6902. // private
  6903. allowContainerRemove: false,
  6904. // private
  6905. isValidParent : function(c, target){
  6906. return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
  6907. },
  6908. getLayoutTargetSize : function() {
  6909. var target = this.container.getLayoutTarget(), ret;
  6910. if (target) {
  6911. ret = target.getViewSize();
  6912. // IE in strict mode will return a height of 0 on the 1st pass of getViewSize.
  6913. // Use getStyleSize to verify the 0 height, the adjustment pass will then work properly
  6914. // with getViewSize
  6915. if (Ext.isIE && Ext.isStrict && ret.height == 0){
  6916. ret = target.getStyleSize();
  6917. }
  6918. ret.width -= target.getPadding('lr');
  6919. ret.height -= target.getPadding('tb');
  6920. }
  6921. return ret;
  6922. },
  6923. renderAll : function(ct, target) {
  6924. if(!this.innerCt){
  6925. // the innerCt prevents wrapping and shuffling while
  6926. // the container is resizing
  6927. this.innerCt = target.createChild({cls:'x-column-inner'});
  6928. this.innerCt.createChild({cls:'x-clear'});
  6929. }
  6930. Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
  6931. },
  6932. // private
  6933. onLayout : function(ct, target){
  6934. var rs = ct.items.items,
  6935. len = rs.length,
  6936. r,
  6937. m,
  6938. i,
  6939. margins = [];
  6940. this.renderAll(ct, target);
  6941. var size = this.getLayoutTargetSize();
  6942. if(size.width < 1 && size.height < 1){ // display none?
  6943. return;
  6944. }
  6945. var h = size.height,
  6946. ph = h;
  6947. this.innerCt.setSize({height:h});
  6948. // some rows can be percentages while others are fixed
  6949. // so we need to make 2 passes
  6950. for(i = 0; i < len; i++){
  6951. r = rs[i];
  6952. m = r.getPositionEl().getMargins('tb');
  6953. margins[i] = m;
  6954. if(!r.rowHeight){
  6955. ph -= (r.getHeight() + m);
  6956. }
  6957. }
  6958. ph = ph < 0 ? 0 : ph;
  6959. for(i = 0; i < len; i++){
  6960. r = rs[i];
  6961. m = margins[i];
  6962. if(r.rowHeight){
  6963. r.setSize({height: Math.floor(r.rowHeight*ph) - m});
  6964. }
  6965. }
  6966. // Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
  6967. // spaces were accounted for properly. If not, re-layout.
  6968. if (Ext.isIE) {
  6969. if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
  6970. var ts = this.getLayoutTargetSize();
  6971. if (ts.width != size.width){
  6972. this.adjustmentPass = true;
  6973. this.onLayout(ct, target);
  6974. }
  6975. }
  6976. }
  6977. delete this.adjustmentPass;
  6978. }
  6979. /**
  6980. * @property activeItem
  6981. * @hide
  6982. */
  6983. });
  6984. Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout;
  6985. Ext.ns('Ext.ux.form');
  6986. Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
  6987. initComponent : function(){
  6988. Ext.ux.form.SearchField.superclass.initComponent.call(this);
  6989. this.on('specialkey', function(f, e){
  6990. if(e.getKey() == e.ENTER){
  6991. this.onTrigger2Click();
  6992. }
  6993. }, this);
  6994. },
  6995. validationEvent:false,
  6996. validateOnBlur:false,
  6997. trigger1Class:'x-form-clear-trigger',
  6998. trigger2Class:'x-form-search-trigger',
  6999. hideTrigger1:true,
  7000. width:180,
  7001. hasSearch : false,
  7002. paramName : 'query',
  7003. onTrigger1Click : function(){
  7004. if(this.hasSearch){
  7005. this.el.dom.value = '';
  7006. var o = {start: 0};
  7007. this.store.baseParams = this.store.baseParams || {};
  7008. this.store.baseParams[this.paramName] = '';
  7009. this.store.reload({params:o});
  7010. this.triggers[0].hide();
  7011. this.hasSearch = false;
  7012. }
  7013. },
  7014. onTrigger2Click : function(){
  7015. var v = this.getRawValue();
  7016. if(v.length < 1){
  7017. this.onTrigger1Click();
  7018. return;
  7019. }
  7020. var o = {start: 0};
  7021. this.store.baseParams = this.store.baseParams || {};
  7022. this.store.baseParams[this.paramName] = v;
  7023. this.store.reload({params:o});
  7024. this.hasSearch = true;
  7025. this.triggers[0].show();
  7026. }
  7027. });Ext.ns('Ext.ux.form');
  7028. /**
  7029. * @class Ext.ux.form.SelectBox
  7030. * @extends Ext.form.ComboBox
  7031. * <p>Makes a ComboBox more closely mimic an HTML SELECT. Supports clicking and dragging
  7032. * through the list, with item selection occurring when the mouse button is released.
  7033. * When used will automatically set {@link #editable} to false and call {@link Ext.Element#unselectable}
  7034. * on inner elements. Re-enabling editable after calling this will NOT work.</p>
  7035. * @author Corey Gilmore http://extjs.com/forum/showthread.php?t=6392
  7036. * @history 2007-07-08 jvs
  7037. * Slight mods for Ext 2.0
  7038. * @xtype selectbox
  7039. */
  7040. Ext.ux.form.SelectBox = Ext.extend(Ext.form.ComboBox, {
  7041. constructor: function(config){
  7042. this.searchResetDelay = 1000;
  7043. config = config || {};
  7044. config = Ext.apply(config || {}, {
  7045. editable: false,
  7046. forceSelection: true,
  7047. rowHeight: false,
  7048. lastSearchTerm: false,
  7049. triggerAction: 'all',
  7050. mode: 'local'
  7051. });
  7052. Ext.ux.form.SelectBox.superclass.constructor.apply(this, arguments);
  7053. this.lastSelectedIndex = this.selectedIndex || 0;
  7054. },
  7055. initEvents : function(){
  7056. Ext.ux.form.SelectBox.superclass.initEvents.apply(this, arguments);
  7057. // you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE
  7058. this.el.on('keydown', this.keySearch, this, true);
  7059. this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);
  7060. },
  7061. keySearch : function(e, target, options) {
  7062. var raw = e.getKey();
  7063. var key = String.fromCharCode(raw);
  7064. var startIndex = 0;
  7065. if( !this.store.getCount() ) {
  7066. return;
  7067. }
  7068. switch(raw) {
  7069. case Ext.EventObject.HOME:
  7070. e.stopEvent();
  7071. this.selectFirst();
  7072. return;
  7073. case Ext.EventObject.END:
  7074. e.stopEvent();
  7075. this.selectLast();
  7076. return;
  7077. case Ext.EventObject.PAGEDOWN:
  7078. this.selectNextPage();
  7079. e.stopEvent();
  7080. return;
  7081. case Ext.EventObject.PAGEUP:
  7082. this.selectPrevPage();
  7083. e.stopEvent();
  7084. return;
  7085. }
  7086. // skip special keys other than the shift key
  7087. if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {
  7088. return;
  7089. }
  7090. if( this.lastSearchTerm == key ) {
  7091. startIndex = this.lastSelectedIndex;
  7092. }
  7093. this.search(this.displayField, key, startIndex);
  7094. this.cshTask.delay(this.searchResetDelay);
  7095. },
  7096. onRender : function(ct, position) {
  7097. this.store.on('load', this.calcRowsPerPage, this);
  7098. Ext.ux.form.SelectBox.superclass.onRender.apply(this, arguments);
  7099. if( this.mode == 'local' ) {
  7100. this.initList();
  7101. this.calcRowsPerPage();
  7102. }
  7103. },
  7104. onSelect : function(record, index, skipCollapse){
  7105. if(this.fireEvent('beforeselect', this, record, index) !== false){
  7106. this.setValue(record.data[this.valueField || this.displayField]);
  7107. if( !skipCollapse ) {
  7108. this.collapse();
  7109. }
  7110. this.lastSelectedIndex = index + 1;
  7111. this.fireEvent('select', this, record, index);
  7112. }
  7113. },
  7114. afterRender : function() {
  7115. Ext.ux.form.SelectBox.superclass.afterRender.apply(this, arguments);
  7116. if(Ext.isWebKit) {
  7117. this.el.swallowEvent('mousedown', true);
  7118. }
  7119. this.el.unselectable();
  7120. this.innerList.unselectable();
  7121. this.trigger.unselectable();
  7122. this.innerList.on('mouseup', function(e, target, options) {
  7123. if( target.id && target.id == this.innerList.id ) {
  7124. return;
  7125. }
  7126. this.onViewClick();
  7127. }, this);
  7128. this.innerList.on('mouseover', function(e, target, options) {
  7129. if( target.id && target.id == this.innerList.id ) {
  7130. return;
  7131. }
  7132. this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;
  7133. this.cshTask.delay(this.searchResetDelay);
  7134. }, this);
  7135. this.trigger.un('click', this.onTriggerClick, this);
  7136. this.trigger.on('mousedown', function(e, target, options) {
  7137. e.preventDefault();
  7138. this.onTriggerClick();
  7139. }, this);
  7140. this.on('collapse', function(e, target, options) {
  7141. Ext.getDoc().un('mouseup', this.collapseIf, this);
  7142. }, this, true);
  7143. this.on('expand', function(e, target, options) {
  7144. Ext.getDoc().on('mouseup', this.collapseIf, this);
  7145. }, this, true);
  7146. },
  7147. clearSearchHistory : function() {
  7148. this.lastSelectedIndex = 0;
  7149. this.lastSearchTerm = false;
  7150. },
  7151. selectFirst : function() {
  7152. this.focusAndSelect(this.store.data.first());
  7153. },
  7154. selectLast : function() {
  7155. this.focusAndSelect(this.store.data.last());
  7156. },
  7157. selectPrevPage : function() {
  7158. if( !this.rowHeight ) {
  7159. return;
  7160. }
  7161. var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);
  7162. this.focusAndSelect(this.store.getAt(index));
  7163. },
  7164. selectNextPage : function() {
  7165. if( !this.rowHeight ) {
  7166. return;
  7167. }
  7168. var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);
  7169. this.focusAndSelect(this.store.getAt(index));
  7170. },
  7171. search : function(field, value, startIndex) {
  7172. field = field || this.displayField;
  7173. this.lastSearchTerm = value;
  7174. var index = this.store.find.apply(this.store, arguments);
  7175. if( index !== -1 ) {
  7176. this.focusAndSelect(index);
  7177. }
  7178. },
  7179. focusAndSelect : function(record) {
  7180. var index = Ext.isNumber(record) ? record : this.store.indexOf(record);
  7181. this.select(index, this.isExpanded());
  7182. this.onSelect(this.store.getAt(index), index, this.isExpanded());
  7183. },
  7184. calcRowsPerPage : function() {
  7185. if( this.store.getCount() ) {
  7186. this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();
  7187. this.rowsPerPage = this.maxHeight / this.rowHeight;
  7188. } else {
  7189. this.rowHeight = false;
  7190. }
  7191. }
  7192. });
  7193. Ext.reg('selectbox', Ext.ux.form.SelectBox);
  7194. //backwards compat
  7195. Ext.ux.SelectBox = Ext.ux.form.SelectBox;
  7196. /**
  7197. * Plugin for PagingToolbar which replaces the textfield input with a slider
  7198. */
  7199. Ext.ux.SlidingPager = Ext.extend(Object, {
  7200. init : function(pbar){
  7201. var idx = pbar.items.indexOf(pbar.inputItem);
  7202. Ext.each(pbar.items.getRange(idx - 2, idx + 2), function(c){
  7203. c.hide();
  7204. });
  7205. var slider = new Ext.Slider({
  7206. width: 114,
  7207. minValue: 1,
  7208. maxValue: 1,
  7209. plugins: new Ext.slider.Tip({
  7210. getText : function(thumb) {
  7211. return String.format('Page <b>{0}</b> of <b>{1}</b>', thumb.value, thumb.slider.maxValue);
  7212. }
  7213. }),
  7214. listeners: {
  7215. changecomplete: function(s, v){
  7216. pbar.changePage(v);
  7217. }
  7218. }
  7219. });
  7220. pbar.insert(idx + 1, slider);
  7221. pbar.on({
  7222. change: function(pb, data){
  7223. slider.setMaxValue(data.pages);
  7224. slider.setValue(data.activePage);
  7225. }
  7226. });
  7227. }
  7228. });Ext.ns('Ext.ux.form');
  7229. /**
  7230. * @class Ext.ux.form.SpinnerField
  7231. * @extends Ext.form.NumberField
  7232. * Creates a field utilizing Ext.ux.Spinner
  7233. * @xtype spinnerfield
  7234. */
  7235. Ext.ux.form.SpinnerField = Ext.extend(Ext.form.NumberField, {
  7236. actionMode: 'wrap',
  7237. deferHeight: true,
  7238. autoSize: Ext.emptyFn,
  7239. onBlur: Ext.emptyFn,
  7240. adjustSize: Ext.BoxComponent.prototype.adjustSize,
  7241. constructor: function(config) {
  7242. var spinnerConfig = Ext.copyTo({}, config, 'incrementValue,alternateIncrementValue,accelerate,defaultValue,triggerClass,splitterClass');
  7243. var spl = this.spinner = new Ext.ux.Spinner(spinnerConfig);
  7244. var plugins = config.plugins
  7245. ? (Ext.isArray(config.plugins)
  7246. ? config.plugins.push(spl)
  7247. : [config.plugins, spl])
  7248. : spl;
  7249. Ext.ux.form.SpinnerField.superclass.constructor.call(this, Ext.apply(config, {plugins: plugins}));
  7250. },
  7251. // private
  7252. getResizeEl: function(){
  7253. return this.wrap;
  7254. },
  7255. // private
  7256. getPositionEl: function(){
  7257. return this.wrap;
  7258. },
  7259. // private
  7260. alignErrorIcon: function(){
  7261. if (this.wrap) {
  7262. this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
  7263. }
  7264. },
  7265. validateBlur: function(){
  7266. return true;
  7267. }
  7268. });
  7269. Ext.reg('spinnerfield', Ext.ux.form.SpinnerField);
  7270. //backwards compat
  7271. Ext.form.SpinnerField = Ext.ux.form.SpinnerField;
  7272. /**
  7273. * @class Ext.ux.Spinner
  7274. * @extends Ext.util.Observable
  7275. * Creates a Spinner control utilized by Ext.ux.form.SpinnerField
  7276. */
  7277. Ext.ux.Spinner = Ext.extend(Ext.util.Observable, {
  7278. incrementValue: 1,
  7279. alternateIncrementValue: 5,
  7280. triggerClass: 'x-form-spinner-trigger',
  7281. splitterClass: 'x-form-spinner-splitter',
  7282. alternateKey: Ext.EventObject.shiftKey,
  7283. defaultValue: 0,
  7284. accelerate: false,
  7285. constructor: function(config){
  7286. Ext.ux.Spinner.superclass.constructor.call(this, config);
  7287. Ext.apply(this, config);
  7288. this.mimicing = false;
  7289. },
  7290. init: function(field){
  7291. this.field = field;
  7292. field.afterMethod('onRender', this.doRender, this);
  7293. field.afterMethod('onEnable', this.doEnable, this);
  7294. field.afterMethod('onDisable', this.doDisable, this);
  7295. field.afterMethod('afterRender', this.doAfterRender, this);
  7296. field.afterMethod('onResize', this.doResize, this);
  7297. field.afterMethod('onFocus', this.doFocus, this);
  7298. field.beforeMethod('onDestroy', this.doDestroy, this);
  7299. },
  7300. doRender: function(ct, position){
  7301. var el = this.el = this.field.getEl();
  7302. var f = this.field;
  7303. if (!f.wrap) {
  7304. f.wrap = this.wrap = el.wrap({
  7305. cls: "x-form-field-wrap"
  7306. });
  7307. }
  7308. else {
  7309. this.wrap = f.wrap.addClass('x-form-field-wrap');
  7310. }
  7311. this.trigger = this.wrap.createChild({
  7312. tag: "img",
  7313. src: Ext.BLANK_IMAGE_URL,
  7314. cls: "x-form-trigger " + this.triggerClass
  7315. });
  7316. if (!f.width) {
  7317. this.wrap.setWidth(el.getWidth() + this.trigger.getWidth());
  7318. }
  7319. this.splitter = this.wrap.createChild({
  7320. tag: 'div',
  7321. cls: this.splitterClass,
  7322. style: 'width:13px; height:2px;'
  7323. });
  7324. this.splitter.setRight((Ext.isIE) ? 1 : 2).setTop(10).show();
  7325. this.proxy = this.trigger.createProxy('', this.splitter, true);
  7326. this.proxy.addClass("x-form-spinner-proxy");
  7327. this.proxy.setStyle('left', '0px');
  7328. this.proxy.setSize(14, 1);
  7329. this.proxy.hide();
  7330. this.dd = new Ext.dd.DDProxy(this.splitter.dom.id, "SpinnerDrag", {
  7331. dragElId: this.proxy.id
  7332. });
  7333. this.initTrigger();
  7334. this.initSpinner();
  7335. },
  7336. doAfterRender: function(){
  7337. var y;
  7338. if (Ext.isIE && this.el.getY() != (y = this.trigger.getY())) {
  7339. this.el.position();
  7340. this.el.setY(y);
  7341. }
  7342. },
  7343. doEnable: function(){
  7344. if (this.wrap) {
  7345. this.disabled = false;
  7346. this.wrap.removeClass(this.field.disabledClass);
  7347. }
  7348. },
  7349. doDisable: function(){
  7350. if (this.wrap) {
  7351. this.disabled = true;
  7352. this.wrap.addClass(this.field.disabledClass);
  7353. this.el.removeClass(this.field.disabledClass);
  7354. }
  7355. },
  7356. doResize: function(w, h){
  7357. if (typeof w == 'number') {
  7358. this.el.setWidth(w - this.trigger.getWidth());
  7359. }
  7360. this.wrap.setWidth(this.el.getWidth() + this.trigger.getWidth());
  7361. },
  7362. doFocus: function(){
  7363. if (!this.mimicing) {
  7364. this.wrap.addClass('x-trigger-wrap-focus');
  7365. this.mimicing = true;
  7366. Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {
  7367. delay: 10
  7368. });
  7369. this.el.on('keydown', this.checkTab, this);
  7370. }
  7371. },
  7372. // private
  7373. checkTab: function(e){
  7374. if (e.getKey() == e.TAB) {
  7375. this.triggerBlur();
  7376. }
  7377. },
  7378. // private
  7379. mimicBlur: function(e){
  7380. if (!this.wrap.contains(e.target) && this.field.validateBlur(e)) {
  7381. this.triggerBlur();
  7382. }
  7383. },
  7384. // private
  7385. triggerBlur: function(){
  7386. this.mimicing = false;
  7387. Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
  7388. this.el.un("keydown", this.checkTab, this);
  7389. this.field.beforeBlur();
  7390. this.wrap.removeClass('x-trigger-wrap-focus');
  7391. this.field.onBlur.call(this.field);
  7392. },
  7393. initTrigger: function(){
  7394. this.trigger.addClassOnOver('x-form-trigger-over');
  7395. this.trigger.addClassOnClick('x-form-trigger-click');
  7396. },
  7397. initSpinner: function(){
  7398. this.field.addEvents({
  7399. 'spin': true,
  7400. 'spinup': true,
  7401. 'spindown': true
  7402. });
  7403. this.keyNav = new Ext.KeyNav(this.el, {
  7404. "up": function(e){
  7405. e.preventDefault();
  7406. this.onSpinUp();
  7407. },
  7408. "down": function(e){
  7409. e.preventDefault();
  7410. this.onSpinDown();
  7411. },
  7412. "pageUp": function(e){
  7413. e.preventDefault();
  7414. this.onSpinUpAlternate();
  7415. },
  7416. "pageDown": function(e){
  7417. e.preventDefault();
  7418. this.onSpinDownAlternate();
  7419. },
  7420. scope: this
  7421. });
  7422. this.repeater = new Ext.util.ClickRepeater(this.trigger, {
  7423. accelerate: this.accelerate
  7424. });
  7425. this.field.mon(this.repeater, "click", this.onTriggerClick, this, {
  7426. preventDefault: true
  7427. });
  7428. this.field.mon(this.trigger, {
  7429. mouseover: this.onMouseOver,
  7430. mouseout: this.onMouseOut,
  7431. mousemove: this.onMouseMove,
  7432. mousedown: this.onMouseDown,
  7433. mouseup: this.onMouseUp,
  7434. scope: this,
  7435. preventDefault: true
  7436. });
  7437. this.field.mon(this.wrap, "mousewheel", this.handleMouseWheel, this);
  7438. this.dd.setXConstraint(0, 0, 10)
  7439. this.dd.setYConstraint(1500, 1500, 10);
  7440. this.dd.endDrag = this.endDrag.createDelegate(this);
  7441. this.dd.startDrag = this.startDrag.createDelegate(this);
  7442. this.dd.onDrag = this.onDrag.createDelegate(this);
  7443. },
  7444. onMouseOver: function(){
  7445. if (this.disabled) {
  7446. return;
  7447. }
  7448. var middle = this.getMiddle();
  7449. this.tmpHoverClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-overup' : 'x-form-spinner-overdown';
  7450. this.trigger.addClass(this.tmpHoverClass);
  7451. },
  7452. //private
  7453. onMouseOut: function(){
  7454. this.trigger.removeClass(this.tmpHoverClass);
  7455. },
  7456. //private
  7457. onMouseMove: function(){
  7458. if (this.disabled) {
  7459. return;
  7460. }
  7461. var middle = this.getMiddle();
  7462. if (((Ext.EventObject.getPageY() > middle) && this.tmpHoverClass == "x-form-spinner-overup") ||
  7463. ((Ext.EventObject.getPageY() < middle) && this.tmpHoverClass == "x-form-spinner-overdown")) {
  7464. }
  7465. },
  7466. //private
  7467. onMouseDown: function(){
  7468. if (this.disabled) {
  7469. return;
  7470. }
  7471. var middle = this.getMiddle();
  7472. this.tmpClickClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-clickup' : 'x-form-spinner-clickdown';
  7473. this.trigger.addClass(this.tmpClickClass);
  7474. },
  7475. //private
  7476. onMouseUp: function(){
  7477. this.trigger.removeClass(this.tmpClickClass);
  7478. },
  7479. //private
  7480. onTriggerClick: function(){
  7481. if (this.disabled || this.el.dom.readOnly) {
  7482. return;
  7483. }
  7484. var middle = this.getMiddle();
  7485. var ud = (Ext.EventObject.getPageY() < middle) ? 'Up' : 'Down';
  7486. this['onSpin' + ud]();
  7487. },
  7488. //private
  7489. getMiddle: function(){
  7490. var t = this.trigger.getTop();
  7491. var h = this.trigger.getHeight();
  7492. var middle = t + (h / 2);
  7493. return middle;
  7494. },
  7495. //private
  7496. //checks if control is allowed to spin
  7497. isSpinnable: function(){
  7498. if (this.disabled || this.el.dom.readOnly) {
  7499. Ext.EventObject.preventDefault(); //prevent scrolling when disabled/readonly
  7500. return false;
  7501. }
  7502. return true;
  7503. },
  7504. handleMouseWheel: function(e){
  7505. //disable scrolling when not focused
  7506. if (this.wrap.hasClass('x-trigger-wrap-focus') == false) {
  7507. return;
  7508. }
  7509. var delta = e.getWheelDelta();
  7510. if (delta > 0) {
  7511. this.onSpinUp();
  7512. e.stopEvent();
  7513. }
  7514. else
  7515. if (delta < 0) {
  7516. this.onSpinDown();
  7517. e.stopEvent();
  7518. }
  7519. },
  7520. //private
  7521. startDrag: function(){
  7522. this.proxy.show();
  7523. this._previousY = Ext.fly(this.dd.getDragEl()).getTop();
  7524. },
  7525. //private
  7526. endDrag: function(){
  7527. this.proxy.hide();
  7528. },
  7529. //private
  7530. onDrag: function(){
  7531. if (this.disabled) {
  7532. return;
  7533. }
  7534. var y = Ext.fly(this.dd.getDragEl()).getTop();
  7535. var ud = '';
  7536. if (this._previousY > y) {
  7537. ud = 'Up';
  7538. } //up
  7539. if (this._previousY < y) {
  7540. ud = 'Down';
  7541. } //down
  7542. if (ud != '') {
  7543. this['onSpin' + ud]();
  7544. }
  7545. this._previousY = y;
  7546. },
  7547. //private
  7548. onSpinUp: function(){
  7549. if (this.isSpinnable() == false) {
  7550. return;
  7551. }
  7552. if (Ext.EventObject.shiftKey == true) {
  7553. this.onSpinUpAlternate();
  7554. return;
  7555. }
  7556. else {
  7557. this.spin(false, false);
  7558. }
  7559. this.field.fireEvent("spin", this);
  7560. this.field.fireEvent("spinup", this);
  7561. },
  7562. //private
  7563. onSpinDown: function(){
  7564. if (this.isSpinnable() == false) {
  7565. return;
  7566. }
  7567. if (Ext.EventObject.shiftKey == true) {
  7568. this.onSpinDownAlternate();
  7569. return;
  7570. }
  7571. else {
  7572. this.spin(true, false);
  7573. }
  7574. this.field.fireEvent("spin", this);
  7575. this.field.fireEvent("spindown", this);
  7576. },
  7577. //private
  7578. onSpinUpAlternate: function(){
  7579. if (this.isSpinnable() == false) {
  7580. return;
  7581. }
  7582. this.spin(false, true);
  7583. this.field.fireEvent("spin", this);
  7584. this.field.fireEvent("spinup", this);
  7585. },
  7586. //private
  7587. onSpinDownAlternate: function(){
  7588. if (this.isSpinnable() == false) {
  7589. return;
  7590. }
  7591. this.spin(true, true);
  7592. this.field.fireEvent("spin", this);
  7593. this.field.fireEvent("spindown", this);
  7594. },
  7595. spin: function(down, alternate){
  7596. var v = parseFloat(this.field.getValue());
  7597. var incr = (alternate == true) ? this.alternateIncrementValue : this.incrementValue;
  7598. (down == true) ? v -= incr : v += incr;
  7599. v = (isNaN(v)) ? this.defaultValue : v;
  7600. v = this.fixBoundries(v);
  7601. this.field.setRawValue(v);
  7602. },
  7603. fixBoundries: function(value){
  7604. var v = value;
  7605. if (this.field.minValue != undefined && v < this.field.minValue) {
  7606. v = this.field.minValue;
  7607. }
  7608. if (this.field.maxValue != undefined && v > this.field.maxValue) {
  7609. v = this.field.maxValue;
  7610. }
  7611. return this.fixPrecision(v);
  7612. },
  7613. // private
  7614. fixPrecision: function(value){
  7615. var nan = isNaN(value);
  7616. if (!this.field.allowDecimals || this.field.decimalPrecision == -1 || nan || !value) {
  7617. return nan ? '' : value;
  7618. }
  7619. return parseFloat(parseFloat(value).toFixed(this.field.decimalPrecision));
  7620. },
  7621. doDestroy: function(){
  7622. if (this.trigger) {
  7623. this.trigger.remove();
  7624. }
  7625. if (this.wrap) {
  7626. this.wrap.remove();
  7627. delete this.field.wrap;
  7628. }
  7629. if (this.splitter) {
  7630. this.splitter.remove();
  7631. }
  7632. if (this.dd) {
  7633. this.dd.unreg();
  7634. this.dd = null;
  7635. }
  7636. if (this.proxy) {
  7637. this.proxy.remove();
  7638. }
  7639. if (this.repeater) {
  7640. this.repeater.purgeListeners();
  7641. }
  7642. if (this.mimicing){
  7643. Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
  7644. }
  7645. }
  7646. });
  7647. //backwards compat
  7648. Ext.form.Spinner = Ext.ux.Spinner;Ext.ux.Spotlight = function(config){
  7649. Ext.apply(this, config);
  7650. }
  7651. Ext.ux.Spotlight.prototype = {
  7652. active : false,
  7653. animate : true,
  7654. duration: .25,
  7655. easing:'easeNone',
  7656. // private
  7657. animated : false,
  7658. createElements : function(){
  7659. var bd = Ext.getBody();
  7660. this.right = bd.createChild({cls:'x-spotlight'});
  7661. this.left = bd.createChild({cls:'x-spotlight'});
  7662. this.top = bd.createChild({cls:'x-spotlight'});
  7663. this.bottom = bd.createChild({cls:'x-spotlight'});
  7664. this.all = new Ext.CompositeElement([this.right, this.left, this.top, this.bottom]);
  7665. },
  7666. show : function(el, callback, scope){
  7667. if(this.animated){
  7668. this.show.defer(50, this, [el, callback, scope]);
  7669. return;
  7670. }
  7671. this.el = Ext.get(el);
  7672. if(!this.right){
  7673. this.createElements();
  7674. }
  7675. if(!this.active){
  7676. this.all.setDisplayed('');
  7677. this.applyBounds(true, false);
  7678. this.active = true;
  7679. Ext.EventManager.onWindowResize(this.syncSize, this);
  7680. this.applyBounds(false, this.animate, false, callback, scope);
  7681. }else{
  7682. this.applyBounds(false, false, false, callback, scope); // all these booleans look hideous
  7683. }
  7684. },
  7685. hide : function(callback, scope){
  7686. if(this.animated){
  7687. this.hide.defer(50, this, [callback, scope]);
  7688. return;
  7689. }
  7690. Ext.EventManager.removeResizeListener(this.syncSize, this);
  7691. this.applyBounds(true, this.animate, true, callback, scope);
  7692. },
  7693. doHide : function(){
  7694. this.active = false;
  7695. this.all.setDisplayed(false);
  7696. },
  7697. syncSize : function(){
  7698. this.applyBounds(false, false);
  7699. },
  7700. applyBounds : function(basePts, anim, doHide, callback, scope){
  7701. var rg = this.el.getRegion();
  7702. var dw = Ext.lib.Dom.getViewWidth(true);
  7703. var dh = Ext.lib.Dom.getViewHeight(true);
  7704. var c = 0, cb = false;
  7705. if(anim){
  7706. cb = {
  7707. callback: function(){
  7708. c++;
  7709. if(c == 4){
  7710. this.animated = false;
  7711. if(doHide){
  7712. this.doHide();
  7713. }
  7714. Ext.callback(callback, scope, [this]);
  7715. }
  7716. },
  7717. scope: this,
  7718. duration: this.duration,
  7719. easing: this.easing
  7720. };
  7721. this.animated = true;
  7722. }
  7723. this.right.setBounds(
  7724. rg.right,
  7725. basePts ? dh : rg.top,
  7726. dw - rg.right,
  7727. basePts ? 0 : (dh - rg.top),
  7728. cb);
  7729. this.left.setBounds(
  7730. 0,
  7731. 0,
  7732. rg.left,
  7733. basePts ? 0 : rg.bottom,
  7734. cb);
  7735. this.top.setBounds(
  7736. basePts ? dw : rg.left,
  7737. 0,
  7738. basePts ? 0 : dw - rg.left,
  7739. rg.top,
  7740. cb);
  7741. this.bottom.setBounds(
  7742. 0,
  7743. rg.bottom,
  7744. basePts ? 0 : rg.right,
  7745. dh - rg.bottom,
  7746. cb);
  7747. if(!anim){
  7748. if(doHide){
  7749. this.doHide();
  7750. }
  7751. if(callback){
  7752. Ext.callback(callback, scope, [this]);
  7753. }
  7754. }
  7755. },
  7756. destroy : function(){
  7757. this.doHide();
  7758. Ext.destroy(
  7759. this.right,
  7760. this.left,
  7761. this.top,
  7762. this.bottom);
  7763. delete this.el;
  7764. delete this.all;
  7765. }
  7766. };
  7767. //backwards compat
  7768. Ext.Spotlight = Ext.ux.Spotlight;/**
  7769. * @class Ext.ux.StatusBar
  7770. * <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}. In addition to
  7771. * supporting the standard {@link Ext.Toolbar} interface for adding buttons, menus and other items, the StatusBar
  7772. * provides a greedy status element that can be aligned to either side and has convenient methods for setting the
  7773. * status text and icon. You can also indicate that something is processing using the {@link #showBusy} method.</p>
  7774. * <pre><code>
  7775. new Ext.Panel({
  7776. title: 'StatusBar',
  7777. // etc.
  7778. bbar: new Ext.ux.StatusBar({
  7779. id: 'my-status',
  7780. // defaults to use when the status is cleared:
  7781. defaultText: 'Default status text',
  7782. defaultIconCls: 'default-icon',
  7783. // values to set initially:
  7784. text: 'Ready',
  7785. iconCls: 'ready-icon',
  7786. // any standard Toolbar items:
  7787. items: [{
  7788. text: 'A Button'
  7789. }, '-', 'Plain Text']
  7790. })
  7791. });
  7792. // Update the status bar later in code:
  7793. var sb = Ext.getCmp('my-status');
  7794. sb.setStatus({
  7795. text: 'OK',
  7796. iconCls: 'ok-icon',
  7797. clear: true // auto-clear after a set interval
  7798. });
  7799. // Set the status bar to show that something is processing:
  7800. sb.showBusy();
  7801. // processing....
  7802. sb.clearStatus(); // once completeed
  7803. </code></pre>
  7804. * @extends Ext.Toolbar
  7805. * @constructor
  7806. * Creates a new StatusBar
  7807. * @param {Object/Array} config A config object
  7808. */
  7809. Ext.ux.StatusBar = Ext.extend(Ext.Toolbar, {
  7810. /**
  7811. * @cfg {String} statusAlign
  7812. * The alignment of the status element within the overall StatusBar layout. When the StatusBar is rendered,
  7813. * it creates an internal div containing the status text and icon. Any additional Toolbar items added in the
  7814. * StatusBar's {@link #items} config, or added via {@link #add} or any of the supported add* methods, will be
  7815. * rendered, in added order, to the opposite side. The status element is greedy, so it will automatically
  7816. * expand to take up all sapce left over by any other items. Example usage:
  7817. * <pre><code>
  7818. // Create a left-aligned status bar containing a button,
  7819. // separator and text item that will be right-aligned (default):
  7820. new Ext.Panel({
  7821. title: 'StatusBar',
  7822. // etc.
  7823. bbar: new Ext.ux.StatusBar({
  7824. defaultText: 'Default status text',
  7825. id: 'status-id',
  7826. items: [{
  7827. text: 'A Button'
  7828. }, '-', 'Plain Text']
  7829. })
  7830. });
  7831. // By adding the statusAlign config, this will create the
  7832. // exact same toolbar, except the status and toolbar item
  7833. // layout will be reversed from the previous example:
  7834. new Ext.Panel({
  7835. title: 'StatusBar',
  7836. // etc.
  7837. bbar: new Ext.ux.StatusBar({
  7838. defaultText: 'Default status text',
  7839. id: 'status-id',
  7840. statusAlign: 'right',
  7841. items: [{
  7842. text: 'A Button'
  7843. }, '-', 'Plain Text']
  7844. })
  7845. });
  7846. </code></pre>
  7847. */
  7848. /**
  7849. * @cfg {String} defaultText
  7850. * The default {@link #text} value. This will be used anytime the status bar is cleared with the
  7851. * <tt>useDefaults:true</tt> option (defaults to '').
  7852. */
  7853. /**
  7854. * @cfg {String} defaultIconCls
  7855. * The default {@link #iconCls} value (see the iconCls docs for additional details about customizing the icon).
  7856. * This will be used anytime the status bar is cleared with the <tt>useDefaults:true</tt> option (defaults to '').
  7857. */
  7858. /**
  7859. * @cfg {String} text
  7860. * A string that will be <b>initially</b> set as the status message. This string
  7861. * will be set as innerHTML (html tags are accepted) for the toolbar item.
  7862. * If not specified, the value set for <code>{@link #defaultText}</code>
  7863. * will be used.
  7864. */
  7865. /**
  7866. * @cfg {String} iconCls
  7867. * A CSS class that will be <b>initially</b> set as the status bar icon and is
  7868. * expected to provide a background image (defaults to '').
  7869. * Example usage:<pre><code>
  7870. // Example CSS rule:
  7871. .x-statusbar .x-status-custom {
  7872. padding-left: 25px;
  7873. background: transparent url(images/custom-icon.gif) no-repeat 3px 2px;
  7874. }
  7875. // Setting a default icon:
  7876. var sb = new Ext.ux.StatusBar({
  7877. defaultIconCls: 'x-status-custom'
  7878. });
  7879. // Changing the icon:
  7880. sb.setStatus({
  7881. text: 'New status',
  7882. iconCls: 'x-status-custom'
  7883. });
  7884. </code></pre>
  7885. */
  7886. /**
  7887. * @cfg {String} cls
  7888. * The base class applied to the containing element for this component on render (defaults to 'x-statusbar')
  7889. */
  7890. cls : 'x-statusbar',
  7891. /**
  7892. * @cfg {String} busyIconCls
  7893. * The default <code>{@link #iconCls}</code> applied when calling
  7894. * <code>{@link #showBusy}</code> (defaults to <tt>'x-status-busy'</tt>).
  7895. * It can be overridden at any time by passing the <code>iconCls</code>
  7896. * argument into <code>{@link #showBusy}</code>.
  7897. */
  7898. busyIconCls : 'x-status-busy',
  7899. /**
  7900. * @cfg {String} busyText
  7901. * The default <code>{@link #text}</code> applied when calling
  7902. * <code>{@link #showBusy}</code> (defaults to <tt>'Loading...'</tt>).
  7903. * It can be overridden at any time by passing the <code>text</code>
  7904. * argument into <code>{@link #showBusy}</code>.
  7905. */
  7906. busyText : 'Loading...',
  7907. /**
  7908. * @cfg {Number} autoClear
  7909. * The number of milliseconds to wait after setting the status via
  7910. * <code>{@link #setStatus}</code> before automatically clearing the status
  7911. * text and icon (defaults to <tt>5000</tt>). Note that this only applies
  7912. * when passing the <tt>clear</tt> argument to <code>{@link #setStatus}</code>
  7913. * since that is the only way to defer clearing the status. This can
  7914. * be overridden by specifying a different <tt>wait</tt> value in
  7915. * <code>{@link #setStatus}</code>. Calls to <code>{@link #clearStatus}</code>
  7916. * always clear the status bar immediately and ignore this value.
  7917. */
  7918. autoClear : 5000,
  7919. /**
  7920. * @cfg {String} emptyText
  7921. * The text string to use if no text has been set. Defaults to
  7922. * <tt>'&nbsp;'</tt>). If there are no other items in the toolbar using
  7923. * an empty string (<tt>''</tt>) for this value would end up in the toolbar
  7924. * height collapsing since the empty string will not maintain the toolbar
  7925. * height. Use <tt>''</tt> if the toolbar should collapse in height
  7926. * vertically when no text is specified and there are no other items in
  7927. * the toolbar.
  7928. */
  7929. emptyText : '&nbsp;',
  7930. // private
  7931. activeThreadId : 0,
  7932. // private
  7933. initComponent : function(){
  7934. if(this.statusAlign=='right'){
  7935. this.cls += ' x-status-right';
  7936. }
  7937. Ext.ux.StatusBar.superclass.initComponent.call(this);
  7938. },
  7939. // private
  7940. afterRender : function(){
  7941. Ext.ux.StatusBar.superclass.afterRender.call(this);
  7942. var right = this.statusAlign == 'right';
  7943. this.currIconCls = this.iconCls || this.defaultIconCls;
  7944. this.statusEl = new Ext.Toolbar.TextItem({
  7945. cls: 'x-status-text ' + (this.currIconCls || ''),
  7946. text: this.text || this.defaultText || ''
  7947. });
  7948. if(right){
  7949. this.add('->');
  7950. this.add(this.statusEl);
  7951. }else{
  7952. this.insert(0, this.statusEl);
  7953. this.insert(1, '->');
  7954. }
  7955. this.doLayout();
  7956. },
  7957. /**
  7958. * Sets the status {@link #text} and/or {@link #iconCls}. Also supports automatically clearing the
  7959. * status that was set after a specified interval.
  7960. * @param {Object/String} config A config object specifying what status to set, or a string assumed
  7961. * to be the status text (and all other options are defaulted as explained below). A config
  7962. * object containing any or all of the following properties can be passed:<ul>
  7963. * <li><tt>text</tt> {String} : (optional) The status text to display. If not specified, any current
  7964. * status text will remain unchanged.</li>
  7965. * <li><tt>iconCls</tt> {String} : (optional) The CSS class used to customize the status icon (see
  7966. * {@link #iconCls} for details). If not specified, any current iconCls will remain unchanged.</li>
  7967. * <li><tt>clear</tt> {Boolean/Number/Object} : (optional) Allows you to set an internal callback that will
  7968. * automatically clear the status text and iconCls after a specified amount of time has passed. If clear is not
  7969. * specified, the new status will not be auto-cleared and will stay until updated again or cleared using
  7970. * {@link #clearStatus}. If <tt>true</tt> is passed, the status will be cleared using {@link #autoClear},
  7971. * {@link #defaultText} and {@link #defaultIconCls} via a fade out animation. If a numeric value is passed,
  7972. * it will be used as the callback interval (in milliseconds), overriding the {@link #autoClear} value.
  7973. * All other options will be defaulted as with the boolean option. To customize any other options,
  7974. * you can pass an object in the format:<ul>
  7975. * <li><tt>wait</tt> {Number} : (optional) The number of milliseconds to wait before clearing
  7976. * (defaults to {@link #autoClear}).</li>
  7977. * <li><tt>anim</tt> {Number} : (optional) False to clear the status immediately once the callback
  7978. * executes (defaults to true which fades the status out).</li>
  7979. * <li><tt>useDefaults</tt> {Number} : (optional) False to completely clear the status text and iconCls
  7980. * (defaults to true which uses {@link #defaultText} and {@link #defaultIconCls}).</li>
  7981. * </ul></li></ul>
  7982. * Example usage:<pre><code>
  7983. // Simple call to update the text
  7984. statusBar.setStatus('New status');
  7985. // Set the status and icon, auto-clearing with default options:
  7986. statusBar.setStatus({
  7987. text: 'New status',
  7988. iconCls: 'x-status-custom',
  7989. clear: true
  7990. });
  7991. // Auto-clear with custom options:
  7992. statusBar.setStatus({
  7993. text: 'New status',
  7994. iconCls: 'x-status-custom',
  7995. clear: {
  7996. wait: 8000,
  7997. anim: false,
  7998. useDefaults: false
  7999. }
  8000. });
  8001. </code></pre>
  8002. * @return {Ext.ux.StatusBar} this
  8003. */
  8004. setStatus : function(o){
  8005. o = o || {};
  8006. if(typeof o == 'string'){
  8007. o = {text:o};
  8008. }
  8009. if(o.text !== undefined){
  8010. this.setText(o.text);
  8011. }
  8012. if(o.iconCls !== undefined){
  8013. this.setIcon(o.iconCls);
  8014. }
  8015. if(o.clear){
  8016. var c = o.clear,
  8017. wait = this.autoClear,
  8018. defaults = {useDefaults: true, anim: true};
  8019. if(typeof c == 'object'){
  8020. c = Ext.applyIf(c, defaults);
  8021. if(c.wait){
  8022. wait = c.wait;
  8023. }
  8024. }else if(typeof c == 'number'){
  8025. wait = c;
  8026. c = defaults;
  8027. }else if(typeof c == 'boolean'){
  8028. c = defaults;
  8029. }
  8030. c.threadId = this.activeThreadId;
  8031. this.clearStatus.defer(wait, this, [c]);
  8032. }
  8033. return this;
  8034. },
  8035. /**
  8036. * Clears the status {@link #text} and {@link #iconCls}. Also supports clearing via an optional fade out animation.
  8037. * @param {Object} config (optional) A config object containing any or all of the following properties. If this
  8038. * object is not specified the status will be cleared using the defaults below:<ul>
  8039. * <li><tt>anim</tt> {Boolean} : (optional) True to clear the status by fading out the status element (defaults
  8040. * to false which clears immediately).</li>
  8041. * <li><tt>useDefaults</tt> {Boolean} : (optional) True to reset the text and icon using {@link #defaultText} and
  8042. * {@link #defaultIconCls} (defaults to false which sets the text to '' and removes any existing icon class).</li>
  8043. * </ul>
  8044. * @return {Ext.ux.StatusBar} this
  8045. */
  8046. clearStatus : function(o){
  8047. o = o || {};
  8048. if(o.threadId && o.threadId !== this.activeThreadId){
  8049. // this means the current call was made internally, but a newer
  8050. // thread has set a message since this call was deferred. Since
  8051. // we don't want to overwrite a newer message just ignore.
  8052. return this;
  8053. }
  8054. var text = o.useDefaults ? this.defaultText : this.emptyText,
  8055. iconCls = o.useDefaults ? (this.defaultIconCls ? this.defaultIconCls : '') : '';
  8056. if(o.anim){
  8057. // animate the statusEl Ext.Element
  8058. this.statusEl.el.fadeOut({
  8059. remove: false,
  8060. useDisplay: true,
  8061. scope: this,
  8062. callback: function(){
  8063. this.setStatus({
  8064. text: text,
  8065. iconCls: iconCls
  8066. });
  8067. this.statusEl.el.show();
  8068. }
  8069. });
  8070. }else{
  8071. // hide/show the el to avoid jumpy text or icon
  8072. this.statusEl.hide();
  8073. this.setStatus({
  8074. text: text,
  8075. iconCls: iconCls
  8076. });
  8077. this.statusEl.show();
  8078. }
  8079. return this;
  8080. },
  8081. /**
  8082. * Convenience method for setting the status text directly. For more flexible options see {@link #setStatus}.
  8083. * @param {String} text (optional) The text to set (defaults to '')
  8084. * @return {Ext.ux.StatusBar} this
  8085. */
  8086. setText : function(text){
  8087. this.activeThreadId++;
  8088. this.text = text || '';
  8089. if(this.rendered){
  8090. this.statusEl.setText(this.text);
  8091. }
  8092. return this;
  8093. },
  8094. /**
  8095. * Returns the current status text.
  8096. * @return {String} The status text
  8097. */
  8098. getText : function(){
  8099. return this.text;
  8100. },
  8101. /**
  8102. * Convenience method for setting the status icon directly. For more flexible options see {@link #setStatus}.
  8103. * See {@link #iconCls} for complete details about customizing the icon.
  8104. * @param {String} iconCls (optional) The icon class to set (defaults to '', and any current icon class is removed)
  8105. * @return {Ext.ux.StatusBar} this
  8106. */
  8107. setIcon : function(cls){
  8108. this.activeThreadId++;
  8109. cls = cls || '';
  8110. if(this.rendered){
  8111. if(this.currIconCls){
  8112. this.statusEl.removeClass(this.currIconCls);
  8113. this.currIconCls = null;
  8114. }
  8115. if(cls.length > 0){
  8116. this.statusEl.addClass(cls);
  8117. this.currIconCls = cls;
  8118. }
  8119. }else{
  8120. this.currIconCls = cls;
  8121. }
  8122. return this;
  8123. },
  8124. /**
  8125. * Convenience method for setting the status text and icon to special values that are pre-configured to indicate
  8126. * a "busy" state, usually for loading or processing activities.
  8127. * @param {Object/String} config (optional) A config object in the same format supported by {@link #setStatus}, or a
  8128. * string to use as the status text (in which case all other options for setStatus will be defaulted). Use the
  8129. * <tt>text</tt> and/or <tt>iconCls</tt> properties on the config to override the default {@link #busyText}
  8130. * and {@link #busyIconCls} settings. If the config argument is not specified, {@link #busyText} and
  8131. * {@link #busyIconCls} will be used in conjunction with all of the default options for {@link #setStatus}.
  8132. * @return {Ext.ux.StatusBar} this
  8133. */
  8134. showBusy : function(o){
  8135. if(typeof o == 'string'){
  8136. o = {text:o};
  8137. }
  8138. o = Ext.applyIf(o || {}, {
  8139. text: this.busyText,
  8140. iconCls: this.busyIconCls
  8141. });
  8142. return this.setStatus(o);
  8143. }
  8144. });
  8145. Ext.reg('statusbar', Ext.ux.StatusBar);
  8146. /**
  8147. * @class Ext.ux.TabCloseMenu
  8148. * @extends Object
  8149. * Plugin (ptype = 'tabclosemenu') for adding a close context menu to tabs. Note that the menu respects
  8150. * the closable configuration on the tab. As such, commands like remove others and remove all will not
  8151. * remove items that are not closable.
  8152. *
  8153. * @constructor
  8154. * @param {Object} config The configuration options
  8155. * @ptype tabclosemenu
  8156. */
  8157. Ext.ux.TabCloseMenu = Ext.extend(Object, {
  8158. /**
  8159. * @cfg {String} closeTabText
  8160. * The text for closing the current tab. Defaults to <tt>'Close Tab'</tt>.
  8161. */
  8162. closeTabText: 'Close Tab',
  8163. /**
  8164. * @cfg {String} closeOtherTabsText
  8165. * The text for closing all tabs except the current one. Defaults to <tt>'Close Other Tabs'</tt>.
  8166. */
  8167. closeOtherTabsText: 'Close Other Tabs',
  8168. /**
  8169. * @cfg {Boolean} showCloseAll
  8170. * Indicates whether to show the 'Close All' option. Defaults to <tt>true</tt>.
  8171. */
  8172. showCloseAll: true,
  8173. /**
  8174. * @cfg {String} closeAllTabsText
  8175. * <p>The text for closing all tabs. Defaults to <tt>'Close All Tabs'</tt>.
  8176. */
  8177. closeAllTabsText: 'Close All Tabs',
  8178. constructor : function(config){
  8179. Ext.apply(this, config || {});
  8180. },
  8181. //public
  8182. init : function(tabs){
  8183. this.tabs = tabs;
  8184. tabs.on({
  8185. scope: this,
  8186. contextmenu: this.onContextMenu,
  8187. destroy: this.destroy
  8188. });
  8189. },
  8190. destroy : function(){
  8191. Ext.destroy(this.menu);
  8192. delete this.menu;
  8193. delete this.tabs;
  8194. delete this.active;
  8195. },
  8196. // private
  8197. onContextMenu : function(tabs, item, e){
  8198. this.active = item;
  8199. var m = this.createMenu(),
  8200. disableAll = true,
  8201. disableOthers = true,
  8202. closeAll = m.getComponent('closeall');
  8203. m.getComponent('close').setDisabled(!item.closable);
  8204. tabs.items.each(function(){
  8205. if(this.closable){
  8206. disableAll = false;
  8207. if(this != item){
  8208. disableOthers = false;
  8209. return false;
  8210. }
  8211. }
  8212. });
  8213. m.getComponent('closeothers').setDisabled(disableOthers);
  8214. if(closeAll){
  8215. closeAll.setDisabled(disableAll);
  8216. }
  8217. e.stopEvent();
  8218. m.showAt(e.getPoint());
  8219. },
  8220. createMenu : function(){
  8221. if(!this.menu){
  8222. var items = [{
  8223. itemId: 'close',
  8224. text: this.closeTabText,
  8225. scope: this,
  8226. handler: this.onClose
  8227. }];
  8228. if(this.showCloseAll){
  8229. items.push('-');
  8230. }
  8231. items.push({
  8232. itemId: 'closeothers',
  8233. text: this.closeOtherTabsText,
  8234. scope: this,
  8235. handler: this.onCloseOthers
  8236. });
  8237. if(this.showCloseAll){
  8238. items.push({
  8239. itemId: 'closeall',
  8240. text: this.closeAllTabsText,
  8241. scope: this,
  8242. handler: this.onCloseAll
  8243. });
  8244. }
  8245. this.menu = new Ext.menu.Menu({
  8246. items: items
  8247. });
  8248. }
  8249. return this.menu;
  8250. },
  8251. onClose : function(){
  8252. this.tabs.remove(this.active);
  8253. },
  8254. onCloseOthers : function(){
  8255. this.doClose(true);
  8256. },
  8257. onCloseAll : function(){
  8258. this.doClose(false);
  8259. },
  8260. doClose : function(excludeActive){
  8261. var items = [];
  8262. this.tabs.items.each(function(item){
  8263. if(item.closable){
  8264. if(!excludeActive || item != this.active){
  8265. items.push(item);
  8266. }
  8267. }
  8268. }, this);
  8269. Ext.each(items, function(item){
  8270. this.tabs.remove(item);
  8271. }, this);
  8272. }
  8273. });
  8274. Ext.preg('tabclosemenu', Ext.ux.TabCloseMenu);Ext.ns('Ext.ux.grid');
  8275. /**
  8276. * @class Ext.ux.grid.TableGrid
  8277. * @extends Ext.grid.GridPanel
  8278. * A Grid which creates itself from an existing HTML table element.
  8279. * @history
  8280. * 2007-03-01 Original version by Nige "Animal" White
  8281. * 2007-03-10 jvs Slightly refactored to reuse existing classes * @constructor
  8282. * @param {String/HTMLElement/Ext.Element} table The table element from which this grid will be created -
  8283. * The table MUST have some type of size defined for the grid to fill. The container will be
  8284. * automatically set to position relative if it isn't already.
  8285. * @param {Object} config A config object that sets properties on this grid and has two additional (optional)
  8286. * properties: fields and columns which allow for customizing data fields and columns for this grid.
  8287. */
  8288. Ext.ux.grid.TableGrid = function(table, config){
  8289. config = config ||
  8290. {};
  8291. Ext.apply(this, config);
  8292. var cf = config.fields || [], ch = config.columns || [];
  8293. table = Ext.get(table);
  8294. var ct = table.insertSibling();
  8295. var fields = [], cols = [];
  8296. var headers = table.query("thead th");
  8297. for (var i = 0, h; h = headers[i]; i++) {
  8298. var text = h.innerHTML;
  8299. var name = 'tcol-' + i;
  8300. fields.push(Ext.applyIf(cf[i] ||
  8301. {}, {
  8302. name: name,
  8303. mapping: 'td:nth(' + (i + 1) + ')/@innerHTML'
  8304. }));
  8305. cols.push(Ext.applyIf(ch[i] ||
  8306. {}, {
  8307. 'header': text,
  8308. 'dataIndex': name,
  8309. 'width': h.offsetWidth,
  8310. 'tooltip': h.title,
  8311. 'sortable': true
  8312. }));
  8313. }
  8314. var ds = new Ext.data.Store({
  8315. reader: new Ext.data.XmlReader({
  8316. record: 'tbody tr'
  8317. }, fields)
  8318. });
  8319. ds.loadData(table.dom);
  8320. var cm = new Ext.grid.ColumnModel(cols);
  8321. if (config.width || config.height) {
  8322. ct.setSize(config.width || 'auto', config.height || 'auto');
  8323. }
  8324. else {
  8325. ct.setWidth(table.getWidth());
  8326. }
  8327. if (config.remove !== false) {
  8328. table.remove();
  8329. }
  8330. Ext.applyIf(this, {
  8331. 'ds': ds,
  8332. 'cm': cm,
  8333. 'sm': new Ext.grid.RowSelectionModel(),
  8334. autoHeight: true,
  8335. autoWidth: false
  8336. });
  8337. Ext.ux.grid.TableGrid.superclass.constructor.call(this, ct, {});
  8338. };
  8339. Ext.extend(Ext.ux.grid.TableGrid, Ext.grid.GridPanel);
  8340. //backwards compat
  8341. Ext.grid.TableGrid = Ext.ux.grid.TableGrid;
  8342. Ext.ns('Ext.ux');
  8343. /**
  8344. * @class Ext.ux.TabScrollerMenu
  8345. * @extends Object
  8346. * Plugin (ptype = 'tabscrollermenu') for adding a tab scroller menu to tabs.
  8347. * @constructor
  8348. * @param {Object} config Configuration options
  8349. * @ptype tabscrollermenu
  8350. */
  8351. Ext.ux.TabScrollerMenu = Ext.extend(Object, {
  8352. /**
  8353. * @cfg {Number} pageSize How many items to allow per submenu.
  8354. */
  8355. pageSize : 10,
  8356. /**
  8357. * @cfg {Number} maxText How long should the title of each {@link Ext.menu.Item} be.
  8358. */
  8359. maxText : 15,
  8360. /**
  8361. * @cfg {String} menuPrefixText Text to prefix the submenus.
  8362. */
  8363. menuPrefixText : 'Items',
  8364. constructor : function(config) {
  8365. config = config || {};
  8366. Ext.apply(this, config);
  8367. },
  8368. //private
  8369. init : function(tabPanel) {
  8370. Ext.apply(tabPanel, this.parentOverrides);
  8371. tabPanel.tabScrollerMenu = this;
  8372. var thisRef = this;
  8373. tabPanel.on({
  8374. render : {
  8375. scope : tabPanel,
  8376. single : true,
  8377. fn : function() {
  8378. var newFn = tabPanel.createScrollers.createSequence(thisRef.createPanelsMenu, this);
  8379. tabPanel.createScrollers = newFn;
  8380. }
  8381. }
  8382. });
  8383. },
  8384. // private && sequeneced
  8385. createPanelsMenu : function() {
  8386. var h = this.stripWrap.dom.offsetHeight;
  8387. //move the right menu item to the left 18px
  8388. var rtScrBtn = this.header.dom.firstChild;
  8389. Ext.fly(rtScrBtn).applyStyles({
  8390. right : '18px'
  8391. });
  8392. var stripWrap = Ext.get(this.strip.dom.parentNode);
  8393. stripWrap.applyStyles({
  8394. 'margin-right' : '36px'
  8395. });
  8396. // Add the new righthand menu
  8397. var scrollMenu = this.header.insertFirst({
  8398. cls:'x-tab-tabmenu-right'
  8399. });
  8400. scrollMenu.setHeight(h);
  8401. scrollMenu.addClassOnOver('x-tab-tabmenu-over');
  8402. scrollMenu.on('click', this.showTabsMenu, this);
  8403. this.scrollLeft.show = this.scrollLeft.show.createSequence(function() {
  8404. scrollMenu.show();
  8405. });
  8406. this.scrollLeft.hide = this.scrollLeft.hide.createSequence(function() {
  8407. scrollMenu.hide();
  8408. });
  8409. },
  8410. /**
  8411. * Returns an the current page size (this.pageSize);
  8412. * @return {Number} this.pageSize The current page size.
  8413. */
  8414. getPageSize : function() {
  8415. return this.pageSize;
  8416. },
  8417. /**
  8418. * Sets the number of menu items per submenu "page size".
  8419. * @param {Number} pageSize The page size
  8420. */
  8421. setPageSize : function(pageSize) {
  8422. this.pageSize = pageSize;
  8423. },
  8424. /**
  8425. * Returns the current maxText length;
  8426. * @return {Number} this.maxText The current max text length.
  8427. */
  8428. getMaxText : function() {
  8429. return this.maxText;
  8430. },
  8431. /**
  8432. * Sets the maximum text size for each menu item.
  8433. * @param {Number} t The max text per each menu item.
  8434. */
  8435. setMaxText : function(t) {
  8436. this.maxText = t;
  8437. },
  8438. /**
  8439. * Returns the current menu prefix text String.;
  8440. * @return {String} this.menuPrefixText The current menu prefix text.
  8441. */
  8442. getMenuPrefixText : function() {
  8443. return this.menuPrefixText;
  8444. },
  8445. /**
  8446. * Sets the menu prefix text String.
  8447. * @param {String} t The menu prefix text.
  8448. */
  8449. setMenuPrefixText : function(t) {
  8450. this.menuPrefixText = t;
  8451. },
  8452. // private && applied to the tab panel itself.
  8453. parentOverrides : {
  8454. // all execute within the scope of the tab panel
  8455. // private
  8456. showTabsMenu : function(e) {
  8457. if (this.tabsMenu) {
  8458. this.tabsMenu.destroy();
  8459. this.un('destroy', this.tabsMenu.destroy, this.tabsMenu);
  8460. this.tabsMenu = null;
  8461. }
  8462. this.tabsMenu = new Ext.menu.Menu();
  8463. this.on('destroy', this.tabsMenu.destroy, this.tabsMenu);
  8464. this.generateTabMenuItems();
  8465. var target = Ext.get(e.getTarget());
  8466. var xy = target.getXY();
  8467. //
  8468. //Y param + 24 pixels
  8469. xy[1] += 24;
  8470. this.tabsMenu.showAt(xy);
  8471. },
  8472. // private
  8473. generateTabMenuItems : function() {
  8474. var curActive = this.getActiveTab();
  8475. var totalItems = this.items.getCount();
  8476. var pageSize = this.tabScrollerMenu.getPageSize();
  8477. if (totalItems > pageSize) {
  8478. var numSubMenus = Math.floor(totalItems / pageSize);
  8479. var remainder = totalItems % pageSize;
  8480. // Loop through all of the items and create submenus in chunks of 10
  8481. for (var i = 0 ; i < numSubMenus; i++) {
  8482. var curPage = (i + 1) * pageSize;
  8483. var menuItems = [];
  8484. for (var x = 0; x < pageSize; x++) {
  8485. index = x + curPage - pageSize;
  8486. var item = this.items.get(index);
  8487. menuItems.push(this.autoGenMenuItem(item));
  8488. }
  8489. this.tabsMenu.add({
  8490. text : this.tabScrollerMenu.getMenuPrefixText() + ' ' + (curPage - pageSize + 1) + ' - ' + curPage,
  8491. menu : menuItems
  8492. });
  8493. }
  8494. // remaining items
  8495. if (remainder > 0) {
  8496. var start = numSubMenus * pageSize;
  8497. menuItems = [];
  8498. for (var i = start ; i < totalItems; i ++ ) {
  8499. var item = this.items.get(i);
  8500. menuItems.push(this.autoGenMenuItem(item));
  8501. }
  8502. this.tabsMenu.add({
  8503. text : this.tabScrollerMenu.menuPrefixText + ' ' + (start + 1) + ' - ' + (start + menuItems.length),
  8504. menu : menuItems
  8505. });
  8506. }
  8507. }
  8508. else {
  8509. this.items.each(function(item) {
  8510. if (item.id != curActive.id && !item.hidden) {
  8511. this.tabsMenu.add(this.autoGenMenuItem(item));
  8512. }
  8513. }, this);
  8514. }
  8515. },
  8516. // private
  8517. autoGenMenuItem : function(item) {
  8518. var maxText = this.tabScrollerMenu.getMaxText();
  8519. var text = Ext.util.Format.ellipsis(item.title, maxText);
  8520. return {
  8521. text : text,
  8522. handler : this.showTabFromMenu,
  8523. scope : this,
  8524. disabled : item.disabled,
  8525. tabToShow : item,
  8526. iconCls : item.iconCls
  8527. }
  8528. },
  8529. // private
  8530. showTabFromMenu : function(menuItem) {
  8531. this.setActiveTab(menuItem.tabToShow);
  8532. }
  8533. }
  8534. });
  8535. Ext.reg('tabscrollermenu', Ext.ux.TabScrollerMenu);
  8536. Ext.ns('Ext.ux.tree');
  8537. /**
  8538. * @class Ext.ux.tree.XmlTreeLoader
  8539. * @extends Ext.tree.TreeLoader
  8540. * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
  8541. * Any text value included as a text node in the XML will be added to the parent node as an attribute
  8542. * called <tt>innerText</tt>. Also, the tag name of each XML node will be added to the tree node as
  8543. * an attribute called <tt>tagName</tt>.</p>
  8544. * <p>By default, this class expects that your source XML will provide the necessary attributes on each
  8545. * node as expected by the {@link Ext.tree.TreePanel} to display and load properly. However, you can
  8546. * provide your own custom processing of node attributes by overriding the {@link #processNode} method
  8547. * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
  8548. * @constructor
  8549. * Creates a new XmlTreeloader.
  8550. * @param {Object} config A config object containing config properties.
  8551. */
  8552. Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
  8553. /**
  8554. * @property XML_NODE_ELEMENT
  8555. * XML element node (value 1, read-only)
  8556. * @type Number
  8557. */
  8558. XML_NODE_ELEMENT : 1,
  8559. /**
  8560. * @property XML_NODE_TEXT
  8561. * XML text node (value 3, read-only)
  8562. * @type Number
  8563. */
  8564. XML_NODE_TEXT : 3,
  8565. // private override
  8566. processResponse : function(response, node, callback){
  8567. var xmlData = response.responseXML,
  8568. root = xmlData.documentElement || xmlData;
  8569. try{
  8570. node.beginUpdate();
  8571. node.appendChild(this.parseXml(root));
  8572. node.endUpdate();
  8573. this.runCallback(callback, scope || node, [node]);
  8574. }catch(e){
  8575. this.handleFailure(response);
  8576. }
  8577. },
  8578. // private
  8579. parseXml : function(node) {
  8580. var nodes = [];
  8581. Ext.each(node.childNodes, function(n){
  8582. if(n.nodeType == this.XML_NODE_ELEMENT){
  8583. var treeNode = this.createNode(n);
  8584. if(n.childNodes.length > 0){
  8585. var child = this.parseXml(n);
  8586. if(typeof child == 'string'){
  8587. treeNode.attributes.innerText = child;
  8588. }else{
  8589. treeNode.appendChild(child);
  8590. }
  8591. }
  8592. nodes.push(treeNode);
  8593. }
  8594. else if(n.nodeType == this.XML_NODE_TEXT){
  8595. var text = n.nodeValue.trim();
  8596. if(text.length > 0){
  8597. return nodes = text;
  8598. }
  8599. }
  8600. }, this);
  8601. return nodes;
  8602. },
  8603. // private override
  8604. createNode : function(node){
  8605. var attr = {
  8606. tagName: node.tagName
  8607. };
  8608. Ext.each(node.attributes, function(a){
  8609. attr[a.nodeName] = a.nodeValue;
  8610. });
  8611. this.processAttributes(attr);
  8612. return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
  8613. },
  8614. /*
  8615. * Template method intended to be overridden by subclasses that need to provide
  8616. * custom attribute processing prior to the creation of each TreeNode. This method
  8617. * will be passed a config object containing existing TreeNode attribute name/value
  8618. * pairs which can be modified as needed directly (no need to return the object).
  8619. */
  8620. processAttributes: Ext.emptyFn
  8621. });
  8622. //backwards compat
  8623. Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;
  8624. /**
  8625. * @class Ext.ux.ValidationStatus
  8626. * A {@link Ext.StatusBar} plugin that provides automatic error notification when the
  8627. * associated form contains validation errors.
  8628. * @extends Ext.Component
  8629. * @constructor
  8630. * Creates a new ValiationStatus plugin
  8631. * @param {Object} config A config object
  8632. */
  8633. Ext.ux.ValidationStatus = Ext.extend(Ext.Component, {
  8634. /**
  8635. * @cfg {String} errorIconCls
  8636. * The {@link #iconCls} value to be applied to the status message when there is a
  8637. * validation error. Defaults to <tt>'x-status-error'</tt>.
  8638. */
  8639. errorIconCls : 'x-status-error',
  8640. /**
  8641. * @cfg {String} errorListCls
  8642. * The css class to be used for the error list when there are validation errors.
  8643. * Defaults to <tt>'x-status-error-list'</tt>.
  8644. */
  8645. errorListCls : 'x-status-error-list',
  8646. /**
  8647. * @cfg {String} validIconCls
  8648. * The {@link #iconCls} value to be applied to the status message when the form
  8649. * validates. Defaults to <tt>'x-status-valid'</tt>.
  8650. */
  8651. validIconCls : 'x-status-valid',
  8652. /**
  8653. * @cfg {String} showText
  8654. * The {@link #text} value to be applied when there is a form validation error.
  8655. * Defaults to <tt>'The form has errors (click for details...)'</tt>.
  8656. */
  8657. showText : 'The form has errors (click for details...)',
  8658. /**
  8659. * @cfg {String} showText
  8660. * The {@link #text} value to display when the error list is displayed.
  8661. * Defaults to <tt>'Click again to hide the error list'</tt>.
  8662. */
  8663. hideText : 'Click again to hide the error list',
  8664. /**
  8665. * @cfg {String} submitText
  8666. * The {@link #text} value to be applied when the form is being submitted.
  8667. * Defaults to <tt>'Saving...'</tt>.
  8668. */
  8669. submitText : 'Saving...',
  8670. // private
  8671. init : function(sb){
  8672. sb.on('render', function(){
  8673. this.statusBar = sb;
  8674. this.monitor = true;
  8675. this.errors = new Ext.util.MixedCollection();
  8676. this.listAlign = (sb.statusAlign=='right' ? 'br-tr?' : 'bl-tl?');
  8677. if(this.form){
  8678. this.form = Ext.getCmp(this.form).getForm();
  8679. this.startMonitoring();
  8680. this.form.on('beforeaction', function(f, action){
  8681. if(action.type == 'submit'){
  8682. // Ignore monitoring while submitting otherwise the field validation
  8683. // events cause the status message to reset too early
  8684. this.monitor = false;
  8685. }
  8686. }, this);
  8687. var startMonitor = function(){
  8688. this.monitor = true;
  8689. };
  8690. this.form.on('actioncomplete', startMonitor, this);
  8691. this.form.on('actionfailed', startMonitor, this);
  8692. }
  8693. }, this, {single:true});
  8694. sb.on({
  8695. scope: this,
  8696. afterlayout:{
  8697. single: true,
  8698. fn: function(){
  8699. // Grab the statusEl after the first layout.
  8700. sb.statusEl.getEl().on('click', this.onStatusClick, this, {buffer:200});
  8701. }
  8702. },
  8703. beforedestroy:{
  8704. single: true,
  8705. fn: this.onDestroy
  8706. }
  8707. });
  8708. },
  8709. // private
  8710. startMonitoring : function(){
  8711. this.form.items.each(function(f){
  8712. f.on('invalid', this.onFieldValidation, this);
  8713. f.on('valid', this.onFieldValidation, this);
  8714. }, this);
  8715. },
  8716. // private
  8717. stopMonitoring : function(){
  8718. this.form.items.each(function(f){
  8719. f.un('invalid', this.onFieldValidation, this);
  8720. f.un('valid', this.onFieldValidation, this);
  8721. }, this);
  8722. },
  8723. // private
  8724. onDestroy : function(){
  8725. this.stopMonitoring();
  8726. this.statusBar.statusEl.un('click', this.onStatusClick, this);
  8727. Ext.ux.ValidationStatus.superclass.onDestroy.call(this);
  8728. },
  8729. // private
  8730. onFieldValidation : function(f, msg){
  8731. if(!this.monitor){
  8732. return false;
  8733. }
  8734. if(msg){
  8735. this.errors.add(f.id, {field:f, msg:msg});
  8736. }else{
  8737. this.errors.removeKey(f.id);
  8738. }
  8739. this.updateErrorList();
  8740. if(this.errors.getCount() > 0){
  8741. if(this.statusBar.getText() != this.showText){
  8742. this.statusBar.setStatus({text:this.showText, iconCls:this.errorIconCls});
  8743. }
  8744. }else{
  8745. this.statusBar.clearStatus().setIcon(this.validIconCls);
  8746. }
  8747. },
  8748. // private
  8749. updateErrorList : function(){
  8750. if(this.errors.getCount() > 0){
  8751. var msg = '<ul>';
  8752. this.errors.each(function(err){
  8753. msg += ('<li id="x-err-'+ err.field.id +'"><a href="#">' + err.msg + '</a></li>');
  8754. }, this);
  8755. this.getMsgEl().update(msg+'</ul>');
  8756. }else{
  8757. this.getMsgEl().update('');
  8758. }
  8759. },
  8760. // private
  8761. getMsgEl : function(){
  8762. if(!this.msgEl){
  8763. this.msgEl = Ext.DomHelper.append(Ext.getBody(), {
  8764. cls: this.errorListCls+' x-hide-offsets'
  8765. }, true);
  8766. this.msgEl.on('click', function(e){
  8767. var t = e.getTarget('li', 10, true);
  8768. if(t){
  8769. Ext.getCmp(t.id.split('x-err-')[1]).focus();
  8770. this.hideErrors();
  8771. }
  8772. }, this, {stopEvent:true}); // prevent anchor click navigation
  8773. }
  8774. return this.msgEl;
  8775. },
  8776. // private
  8777. showErrors : function(){
  8778. this.updateErrorList();
  8779. this.getMsgEl().alignTo(this.statusBar.getEl(), this.listAlign).slideIn('b', {duration:0.3, easing:'easeOut'});
  8780. this.statusBar.setText(this.hideText);
  8781. this.form.getEl().on('click', this.hideErrors, this, {single:true}); // hide if the user clicks directly into the form
  8782. },
  8783. // private
  8784. hideErrors : function(){
  8785. var el = this.getMsgEl();
  8786. if(el.isVisible()){
  8787. el.slideOut('b', {duration:0.2, easing:'easeIn'});
  8788. this.statusBar.setText(this.showText);
  8789. }
  8790. this.form.getEl().un('click', this.hideErrors, this);
  8791. },
  8792. // private
  8793. onStatusClick : function(){
  8794. if(this.getMsgEl().isVisible()){
  8795. this.hideErrors();
  8796. }else if(this.errors.getCount() > 0){
  8797. this.showErrors();
  8798. }
  8799. }
  8800. });(function() {
  8801. Ext.override(Ext.list.Column, {
  8802. init : function() {
  8803. var types = Ext.data.Types,
  8804. st = this.sortType;
  8805. if(this.type){
  8806. if(Ext.isString(this.type)){
  8807. this.type = Ext.data.Types[this.type.toUpperCase()] || types.AUTO;
  8808. }
  8809. }else{
  8810. this.type = types.AUTO;
  8811. }
  8812. // named sortTypes are supported, here we look them up
  8813. if(Ext.isString(st)){
  8814. this.sortType = Ext.data.SortTypes[st];
  8815. }else if(Ext.isEmpty(st)){
  8816. this.sortType = this.type.sortType;
  8817. }
  8818. }
  8819. });
  8820. Ext.tree.Column = Ext.extend(Ext.list.Column, {});
  8821. Ext.tree.NumberColumn = Ext.extend(Ext.list.NumberColumn, {});
  8822. Ext.tree.DateColumn = Ext.extend(Ext.list.DateColumn, {});
  8823. Ext.tree.BooleanColumn = Ext.extend(Ext.list.BooleanColumn, {});
  8824. Ext.reg('tgcolumn', Ext.tree.Column);
  8825. Ext.reg('tgnumbercolumn', Ext.tree.NumberColumn);
  8826. Ext.reg('tgdatecolumn', Ext.tree.DateColumn);
  8827. Ext.reg('tgbooleancolumn', Ext.tree.BooleanColumn);
  8828. })();
  8829. /**
  8830. * @class Ext.ux.tree.TreeGridNodeUI
  8831. * @extends Ext.tree.TreeNodeUI
  8832. */
  8833. Ext.ux.tree.TreeGridNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  8834. isTreeGridNodeUI: true,
  8835. renderElements : function(n, a, targetNode, bulkRender){
  8836. var t = n.getOwnerTree(),
  8837. cols = t.columns,
  8838. c = cols[0],
  8839. i, buf, len;
  8840. this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
  8841. buf = [
  8842. '<tbody class="x-tree-node">',
  8843. '<tr ext:tree-node-id="', n.id ,'" class="x-tree-node-el x-tree-node-leaf ', a.cls, '">',
  8844. '<td class="x-treegrid-col">',
  8845. '<span class="x-tree-node-indent">', this.indentMarkup, "</span>",
  8846. '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
  8847. '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon', (a.icon ? " x-tree-node-inline-icon" : ""), (a.iconCls ? " "+a.iconCls : ""), '" unselectable="on" />',
  8848. '<a hidefocus="on" class="x-tree-node-anchor" href="', a.href ? a.href : '#', '" tabIndex="1" ',
  8849. a.hrefTarget ? ' target="'+a.hrefTarget+'"' : '', '>',
  8850. '<span unselectable="on">', (c.tpl ? c.tpl.apply(a) : a[c.dataIndex] || c.text), '</span></a>',
  8851. '</td>'
  8852. ];
  8853. for(i = 1, len = cols.length; i < len; i++){
  8854. c = cols[i];
  8855. buf.push(
  8856. '<td class="x-treegrid-col ', (c.cls ? c.cls : ''), '">',
  8857. '<div unselectable="on" class="x-treegrid-text"', (c.align ? ' style="text-align: ' + c.align + ';"' : ''), '>',
  8858. (c.tpl ? c.tpl.apply(a) : a[c.dataIndex]),
  8859. '</div>',
  8860. '</td>'
  8861. );
  8862. }
  8863. buf.push(
  8864. '</tr><tr class="x-tree-node-ct"><td colspan="', cols.length, '">',
  8865. '<table class="x-treegrid-node-ct-table" cellpadding="0" cellspacing="0" style="table-layout: fixed; display: none; width: ', t.innerCt.getWidth() ,'px;"><colgroup>'
  8866. );
  8867. for(i = 0, len = cols.length; i<len; i++) {
  8868. buf.push('<col style="width: ', (cols[i].hidden ? 0 : cols[i].width) ,'px;" />');
  8869. }
  8870. buf.push('</colgroup></table></td></tr></tbody>');
  8871. if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
  8872. this.wrap = Ext.DomHelper.insertHtml("beforeBegin", n.nextSibling.ui.getEl(), buf.join(''));
  8873. }else{
  8874. this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(''));
  8875. }
  8876. this.elNode = this.wrap.childNodes[0];
  8877. this.ctNode = this.wrap.childNodes[1].firstChild.firstChild;
  8878. var cs = this.elNode.firstChild.childNodes;
  8879. this.indentNode = cs[0];
  8880. this.ecNode = cs[1];
  8881. this.iconNode = cs[2];
  8882. this.anchor = cs[3];
  8883. this.textNode = cs[3].firstChild;
  8884. },
  8885. // private
  8886. animExpand : function(cb){
  8887. this.ctNode.style.display = "";
  8888. Ext.ux.tree.TreeGridNodeUI.superclass.animExpand.call(this, cb);
  8889. }
  8890. });
  8891. Ext.ux.tree.TreeGridRootNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  8892. isTreeGridNodeUI: true,
  8893. // private
  8894. render : function(){
  8895. if(!this.rendered){
  8896. this.wrap = this.ctNode = this.node.ownerTree.innerCt.dom;
  8897. this.node.expanded = true;
  8898. }
  8899. if(Ext.isWebKit) {
  8900. // weird table-layout: fixed issue in webkit
  8901. var ct = this.ctNode;
  8902. ct.style.tableLayout = null;
  8903. (function() {
  8904. ct.style.tableLayout = 'fixed';
  8905. }).defer(1);
  8906. }
  8907. },
  8908. destroy : function(){
  8909. if(this.elNode){
  8910. Ext.dd.Registry.unregister(this.elNode.id);
  8911. }
  8912. delete this.node;
  8913. },
  8914. collapse : Ext.emptyFn,
  8915. expand : Ext.emptyFn
  8916. });/**
  8917. * @class Ext.tree.ColumnResizer
  8918. * @extends Ext.util.Observable
  8919. */
  8920. Ext.tree.ColumnResizer = Ext.extend(Ext.util.Observable, {
  8921. /**
  8922. * @cfg {Number} minWidth The minimum width the column can be dragged to.
  8923. * Defaults to <tt>14</tt>.
  8924. */
  8925. minWidth: 14,
  8926. constructor: function(config){
  8927. Ext.apply(this, config);
  8928. Ext.tree.ColumnResizer.superclass.constructor.call(this);
  8929. },
  8930. init : function(tree){
  8931. this.tree = tree;
  8932. tree.on('render', this.initEvents, this);
  8933. },
  8934. initEvents : function(tree){
  8935. tree.mon(tree.innerHd, 'mousemove', this.handleHdMove, this);
  8936. this.tracker = new Ext.dd.DragTracker({
  8937. onBeforeStart: this.onBeforeStart.createDelegate(this),
  8938. onStart: this.onStart.createDelegate(this),
  8939. onDrag: this.onDrag.createDelegate(this),
  8940. onEnd: this.onEnd.createDelegate(this),
  8941. tolerance: 3,
  8942. autoStart: 300
  8943. });
  8944. this.tracker.initEl(tree.innerHd);
  8945. tree.on('beforedestroy', this.tracker.destroy, this.tracker);
  8946. },
  8947. handleHdMove : function(e, t){
  8948. var hw = 5,
  8949. x = e.getPageX(),
  8950. hd = e.getTarget('.x-treegrid-hd', 3, true);
  8951. if(hd){
  8952. var r = hd.getRegion(),
  8953. ss = hd.dom.style,
  8954. pn = hd.dom.parentNode;
  8955. if(x - r.left <= hw && hd.dom !== pn.firstChild) {
  8956. var ps = hd.dom.previousSibling;
  8957. while(ps && Ext.fly(ps).hasClass('x-treegrid-hd-hidden')) {
  8958. ps = ps.previousSibling;
  8959. }
  8960. if(ps) {
  8961. this.activeHd = Ext.get(ps);
  8962. ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';
  8963. }
  8964. } else if(r.right - x <= hw) {
  8965. var ns = hd.dom;
  8966. while(ns && Ext.fly(ns).hasClass('x-treegrid-hd-hidden')) {
  8967. ns = ns.previousSibling;
  8968. }
  8969. if(ns) {
  8970. this.activeHd = Ext.get(ns);
  8971. ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';
  8972. }
  8973. } else{
  8974. delete this.activeHd;
  8975. ss.cursor = '';
  8976. }
  8977. }
  8978. },
  8979. onBeforeStart : function(e){
  8980. this.dragHd = this.activeHd;
  8981. return !!this.dragHd;
  8982. },
  8983. onStart : function(e){
  8984. this.dragHeadersDisabled = this.tree.headersDisabled;
  8985. this.tree.headersDisabled = true;
  8986. this.proxy = this.tree.body.createChild({cls:'x-treegrid-resizer'});
  8987. this.proxy.setHeight(this.tree.body.getHeight());
  8988. var x = this.tracker.getXY()[0];
  8989. this.hdX = this.dragHd.getX();
  8990. this.hdIndex = this.tree.findHeaderIndex(this.dragHd);
  8991. this.proxy.setX(this.hdX);
  8992. this.proxy.setWidth(x-this.hdX);
  8993. this.maxWidth = this.tree.outerCt.getWidth() - this.tree.innerBody.translatePoints(this.hdX).left;
  8994. },
  8995. onDrag : function(e){
  8996. var cursorX = this.tracker.getXY()[0];
  8997. this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth));
  8998. },
  8999. onEnd : function(e){
  9000. var nw = this.proxy.getWidth(),
  9001. tree = this.tree,
  9002. disabled = this.dragHeadersDisabled;
  9003. this.proxy.remove();
  9004. delete this.dragHd;
  9005. tree.columns[this.hdIndex].width = nw;
  9006. tree.updateColumnWidths();
  9007. setTimeout(function(){
  9008. tree.headersDisabled = disabled;
  9009. }, 100);
  9010. }
  9011. });Ext.ns('Ext.ux.tree');
  9012. /**
  9013. * @class Ext.ux.tree.TreeGridSorter
  9014. * @extends Ext.tree.TreeSorter
  9015. * Provides sorting of nodes in a {@link Ext.ux.tree.TreeGrid}. The TreeGridSorter automatically monitors events on the
  9016. * associated TreeGrid that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
  9017. * Example usage:<br />
  9018. * <pre><code>
  9019. new Ext.ux.tree.TreeGridSorter(myTreeGrid, {
  9020. folderSort: true,
  9021. dir: "desc",
  9022. sortType: function(node) {
  9023. // sort by a custom, typed attribute:
  9024. return parseInt(node.id, 10);
  9025. }
  9026. });
  9027. </code></pre>
  9028. * @constructor
  9029. * @param {TreeGrid} tree
  9030. * @param {Object} config
  9031. */
  9032. Ext.ux.tree.TreeGridSorter = Ext.extend(Ext.tree.TreeSorter, {
  9033. /**
  9034. * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
  9035. */
  9036. sortClasses : ['sort-asc', 'sort-desc'],
  9037. /**
  9038. * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
  9039. */
  9040. sortAscText : 'Sort Ascending',
  9041. /**
  9042. * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
  9043. */
  9044. sortDescText : 'Sort Descending',
  9045. constructor : function(tree, config) {
  9046. if(!Ext.isObject(config)) {
  9047. config = {
  9048. property: tree.columns[0].dataIndex || 'text',
  9049. folderSort: true
  9050. }
  9051. }
  9052. Ext.ux.tree.TreeGridSorter.superclass.constructor.apply(this, arguments);
  9053. this.tree = tree;
  9054. tree.on('headerclick', this.onHeaderClick, this);
  9055. tree.ddAppendOnly = true;
  9056. var me = this;
  9057. this.defaultSortFn = function(n1, n2){
  9058. var desc = me.dir && me.dir.toLowerCase() == 'desc',
  9059. prop = me.property || 'text',
  9060. sortType = me.sortType,
  9061. caseSensitive = me.caseSensitive === true,
  9062. leafAttr = me.leafAttr || 'leaf',
  9063. attr1 = n1.attributes,
  9064. attr2 = n2.attributes;
  9065. if(me.folderSort){
  9066. if(attr1[leafAttr] && !attr2[leafAttr]){
  9067. return 1;
  9068. }
  9069. if(!attr1[leafAttr] && attr2[leafAttr]){
  9070. return -1;
  9071. }
  9072. }
  9073. var prop1 = attr1[prop],
  9074. prop2 = attr2[prop],
  9075. v1 = sortType ? sortType(prop1) : (caseSensitive ? prop1 : prop1.toUpperCase());
  9076. v2 = sortType ? sortType(prop2) : (caseSensitive ? prop2 : prop2.toUpperCase());
  9077. if(v1 < v2){
  9078. return desc ? +1 : -1;
  9079. }else if(v1 > v2){
  9080. return desc ? -1 : +1;
  9081. }else{
  9082. return 0;
  9083. }
  9084. };
  9085. tree.on('afterrender', this.onAfterTreeRender, this, {single: true});
  9086. tree.on('headermenuclick', this.onHeaderMenuClick, this);
  9087. },
  9088. onAfterTreeRender : function() {
  9089. if(this.tree.hmenu){
  9090. this.tree.hmenu.insert(0,
  9091. {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
  9092. {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
  9093. );
  9094. }
  9095. this.updateSortIcon(0, 'asc');
  9096. },
  9097. onHeaderMenuClick : function(c, id, index) {
  9098. if(id === 'asc' || id === 'desc') {
  9099. this.onHeaderClick(c, null, index);
  9100. return false;
  9101. }
  9102. },
  9103. onHeaderClick : function(c, el, i) {
  9104. if(c && !this.tree.headersDisabled){
  9105. var me = this;
  9106. me.property = c.dataIndex;
  9107. me.dir = c.dir = (c.dir === 'desc' ? 'asc' : 'desc');
  9108. me.sortType = c.sortType;
  9109. me.caseSensitive === Ext.isBoolean(c.caseSensitive) ? c.caseSensitive : this.caseSensitive;
  9110. me.sortFn = c.sortFn || this.defaultSortFn;
  9111. this.tree.root.cascade(function(n) {
  9112. if(!n.isLeaf()) {
  9113. me.updateSort(me.tree, n);
  9114. }
  9115. });
  9116. this.updateSortIcon(i, c.dir);
  9117. }
  9118. },
  9119. // private
  9120. updateSortIcon : function(col, dir){
  9121. var sc = this.sortClasses,
  9122. hds = this.tree.innerHd.select('td').removeClass(sc);
  9123. hds.item(col).addClass(sc[dir == 'desc' ? 1 : 0]);
  9124. }
  9125. });/**
  9126. * @class Ext.ux.tree.TreeGridLoader
  9127. * @extends Ext.tree.TreeLoader
  9128. */
  9129. Ext.ux.tree.TreeGridLoader = Ext.extend(Ext.tree.TreeLoader, {
  9130. createNode : function(attr) {
  9131. if (!attr.uiProvider) {
  9132. attr.uiProvider = Ext.ux.tree.TreeGridNodeUI;
  9133. }
  9134. return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
  9135. }
  9136. });/**
  9137. * @class Ext.ux.tree.TreeGrid
  9138. * @extends Ext.tree.TreePanel
  9139. *
  9140. * @xtype treegrid
  9141. */
  9142. Ext.ux.tree.TreeGrid = Ext.extend(Ext.tree.TreePanel, {
  9143. rootVisible : false,
  9144. useArrows : true,
  9145. lines : false,
  9146. borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
  9147. cls : 'x-treegrid',
  9148. columnResize : true,
  9149. enableSort : true,
  9150. reserveScrollOffset : true,
  9151. enableHdMenu : true,
  9152. columnsText : 'Columns',
  9153. initComponent : function() {
  9154. if(!this.root) {
  9155. this.root = new Ext.tree.AsyncTreeNode({text: 'Root'});
  9156. }
  9157. // initialize the loader
  9158. var l = this.loader;
  9159. if(!l){
  9160. l = new Ext.ux.tree.TreeGridLoader({
  9161. dataUrl: this.dataUrl,
  9162. requestMethod: this.requestMethod,
  9163. store: this.store
  9164. });
  9165. }else if(Ext.isObject(l) && !l.load){
  9166. l = new Ext.ux.tree.TreeGridLoader(l);
  9167. }
  9168. this.loader = l;
  9169. Ext.ux.tree.TreeGrid.superclass.initComponent.call(this);
  9170. this.initColumns();
  9171. if(this.enableSort) {
  9172. this.treeGridSorter = new Ext.ux.tree.TreeGridSorter(this, this.enableSort);
  9173. }
  9174. if(this.columnResize){
  9175. this.colResizer = new Ext.tree.ColumnResizer(this.columnResize);
  9176. this.colResizer.init(this);
  9177. }
  9178. var c = this.columns;
  9179. if(!this.internalTpl){
  9180. this.internalTpl = new Ext.XTemplate(
  9181. '<div class="x-grid3-header">',
  9182. '<div class="x-treegrid-header-inner">',
  9183. '<div class="x-grid3-header-offset">',
  9184. '<table style="table-layout: fixed;" cellspacing="0" cellpadding="0" border="0"><colgroup><tpl for="columns"><col /></tpl></colgroup>',
  9185. '<thead><tr class="x-grid3-hd-row">',
  9186. '<tpl for="columns">',
  9187. '<td class="x-grid3-hd x-grid3-cell x-treegrid-hd" style="text-align: {align};" id="', this.id, '-xlhd-{#}">',
  9188. '<div class="x-grid3-hd-inner x-treegrid-hd-inner" unselectable="on">',
  9189. this.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
  9190. '{header}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
  9191. '</div>',
  9192. '</td></tpl>',
  9193. '</tr></thead>',
  9194. '</table>',
  9195. '</div></div>',
  9196. '</div>',
  9197. '<div class="x-treegrid-root-node">',
  9198. '<table class="x-treegrid-root-table" cellpadding="0" cellspacing="0" style="table-layout: fixed;"></table>',
  9199. '</div>'
  9200. );
  9201. }
  9202. if(!this.colgroupTpl) {
  9203. this.colgroupTpl = new Ext.XTemplate(
  9204. '<colgroup><tpl for="columns"><col style="width: {width}px"/></tpl></colgroup>'
  9205. );
  9206. }
  9207. },
  9208. initColumns : function() {
  9209. var cs = this.columns,
  9210. len = cs.length,
  9211. columns = [],
  9212. i, c;
  9213. for(i = 0; i < len; i++){
  9214. c = cs[i];
  9215. if(!c.isColumn) {
  9216. c.xtype = c.xtype ? (/^tg/.test(c.xtype) ? c.xtype : 'tg' + c.xtype) : 'tgcolumn';
  9217. c = Ext.create(c);
  9218. }
  9219. c.init(this);
  9220. columns.push(c);
  9221. if(this.enableSort !== false && c.sortable !== false) {
  9222. c.sortable = true;
  9223. this.enableSort = true;
  9224. }
  9225. }
  9226. this.columns = columns;
  9227. },
  9228. onRender : function(){
  9229. Ext.tree.TreePanel.superclass.onRender.apply(this, arguments);
  9230. this.el.addClass('x-treegrid');
  9231. this.outerCt = this.body.createChild({
  9232. cls:'x-tree-root-ct x-treegrid-ct ' + (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')
  9233. });
  9234. this.internalTpl.overwrite(this.outerCt, {columns: this.columns});
  9235. this.mainHd = Ext.get(this.outerCt.dom.firstChild);
  9236. this.innerHd = Ext.get(this.mainHd.dom.firstChild);
  9237. this.innerBody = Ext.get(this.outerCt.dom.lastChild);
  9238. this.innerCt = Ext.get(this.innerBody.dom.firstChild);
  9239. this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
  9240. if(this.hideHeaders){
  9241. this.el.child('.x-grid3-header').setDisplayed('none');
  9242. }
  9243. else if(this.enableHdMenu !== false){
  9244. this.hmenu = new Ext.menu.Menu({id: this.id + '-hctx'});
  9245. if(this.enableColumnHide !== false){
  9246. this.colMenu = new Ext.menu.Menu({id: this.id + '-hcols-menu'});
  9247. this.colMenu.on({
  9248. scope: this,
  9249. beforeshow: this.beforeColMenuShow,
  9250. itemclick: this.handleHdMenuClick
  9251. });
  9252. this.hmenu.add({
  9253. itemId:'columns',
  9254. hideOnClick: false,
  9255. text: this.columnsText,
  9256. menu: this.colMenu,
  9257. iconCls: 'x-cols-icon'
  9258. });
  9259. }
  9260. this.hmenu.on('itemclick', this.handleHdMenuClick, this);
  9261. }
  9262. },
  9263. setRootNode : function(node){
  9264. node.attributes.uiProvider = Ext.ux.tree.TreeGridRootNodeUI;
  9265. node = Ext.ux.tree.TreeGrid.superclass.setRootNode.call(this, node);
  9266. if(this.innerCt) {
  9267. this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
  9268. }
  9269. return node;
  9270. },
  9271. clearInnerCt : function(){
  9272. if(Ext.isIE){
  9273. var dom = this.innerCt.dom;
  9274. while(dom.firstChild){
  9275. dom.removeChild(dom.firstChild);
  9276. }
  9277. }else{
  9278. Ext.ux.tree.TreeGrid.superclass.clearInnerCt.call(this);
  9279. }
  9280. },
  9281. initEvents : function() {
  9282. Ext.ux.tree.TreeGrid.superclass.initEvents.apply(this, arguments);
  9283. this.mon(this.innerBody, 'scroll', this.syncScroll, this);
  9284. this.mon(this.innerHd, 'click', this.handleHdDown, this);
  9285. this.mon(this.mainHd, {
  9286. scope: this,
  9287. mouseover: this.handleHdOver,
  9288. mouseout: this.handleHdOut
  9289. });
  9290. },
  9291. onResize : function(w, h) {
  9292. Ext.ux.tree.TreeGrid.superclass.onResize.apply(this, arguments);
  9293. var bd = this.innerBody.dom;
  9294. var hd = this.innerHd.dom;
  9295. if(!bd){
  9296. return;
  9297. }
  9298. if(Ext.isNumber(h)){
  9299. bd.style.height = this.body.getHeight(true) - hd.offsetHeight + 'px';
  9300. }
  9301. if(Ext.isNumber(w)){
  9302. var sw = Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
  9303. if(this.reserveScrollOffset || ((bd.offsetWidth - bd.clientWidth) > 10)){
  9304. this.setScrollOffset(sw);
  9305. }else{
  9306. var me = this;
  9307. setTimeout(function(){
  9308. me.setScrollOffset(bd.offsetWidth - bd.clientWidth > 10 ? sw : 0);
  9309. }, 10);
  9310. }
  9311. }
  9312. },
  9313. updateColumnWidths : function() {
  9314. var cols = this.columns,
  9315. colCount = cols.length,
  9316. groups = this.outerCt.query('colgroup'),
  9317. groupCount = groups.length,
  9318. c, g, i, j;
  9319. for(i = 0; i<colCount; i++) {
  9320. c = cols[i];
  9321. for(j = 0; j<groupCount; j++) {
  9322. g = groups[j];
  9323. g.childNodes[i].style.width = (c.hidden ? 0 : c.width) + 'px';
  9324. }
  9325. }
  9326. for(i = 0, groups = this.innerHd.query('td'), len = groups.length; i<len; i++) {
  9327. c = Ext.fly(groups[i]);
  9328. if(cols[i] && cols[i].hidden) {
  9329. c.addClass('x-treegrid-hd-hidden');
  9330. }
  9331. else {
  9332. c.removeClass('x-treegrid-hd-hidden');
  9333. }
  9334. }
  9335. var tcw = this.getTotalColumnWidth();
  9336. Ext.fly(this.innerHd.dom.firstChild).setWidth(tcw + (this.scrollOffset || 0));
  9337. this.outerCt.select('table').setWidth(tcw);
  9338. this.syncHeaderScroll();
  9339. },
  9340. getVisibleColumns : function() {
  9341. var columns = [],
  9342. cs = this.columns,
  9343. len = cs.length,
  9344. i;
  9345. for(i = 0; i<len; i++) {
  9346. if(!cs[i].hidden) {
  9347. columns.push(cs[i]);
  9348. }
  9349. }
  9350. return columns;
  9351. },
  9352. getTotalColumnWidth : function() {
  9353. var total = 0;
  9354. for(var i = 0, cs = this.getVisibleColumns(), len = cs.length; i<len; i++) {
  9355. total += cs[i].width;
  9356. }
  9357. return total;
  9358. },
  9359. setScrollOffset : function(scrollOffset) {
  9360. this.scrollOffset = scrollOffset;
  9361. this.updateColumnWidths();
  9362. },
  9363. // private
  9364. handleHdDown : function(e, t){
  9365. var hd = e.getTarget('.x-treegrid-hd');
  9366. if(hd && Ext.fly(t).hasClass('x-grid3-hd-btn')){
  9367. var ms = this.hmenu.items,
  9368. cs = this.columns,
  9369. index = this.findHeaderIndex(hd),
  9370. c = cs[index],
  9371. sort = c.sortable;
  9372. e.stopEvent();
  9373. Ext.fly(hd).addClass('x-grid3-hd-menu-open');
  9374. this.hdCtxIndex = index;
  9375. this.fireEvent('headerbuttonclick', ms, c, hd, index);
  9376. this.hmenu.on('hide', function(){
  9377. Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
  9378. }, this, {single:true});
  9379. this.hmenu.show(t, 'tl-bl?');
  9380. }
  9381. else if(hd) {
  9382. var index = this.findHeaderIndex(hd);
  9383. this.fireEvent('headerclick', this.columns[index], hd, index);
  9384. }
  9385. },
  9386. // private
  9387. handleHdOver : function(e, t){
  9388. var hd = e.getTarget('.x-treegrid-hd');
  9389. if(hd && !this.headersDisabled){
  9390. index = this.findHeaderIndex(hd);
  9391. this.activeHdRef = t;
  9392. this.activeHdIndex = index;
  9393. var el = Ext.get(hd);
  9394. this.activeHdRegion = el.getRegion();
  9395. el.addClass('x-grid3-hd-over');
  9396. this.activeHdBtn = el.child('.x-grid3-hd-btn');
  9397. if(this.activeHdBtn){
  9398. this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
  9399. }
  9400. }
  9401. },
  9402. // private
  9403. handleHdOut : function(e, t){
  9404. var hd = e.getTarget('.x-treegrid-hd');
  9405. if(hd && (!Ext.isIE || !e.within(hd, true))){
  9406. this.activeHdRef = null;
  9407. Ext.fly(hd).removeClass('x-grid3-hd-over');
  9408. hd.style.cursor = '';
  9409. }
  9410. },
  9411. findHeaderIndex : function(hd){
  9412. hd = hd.dom || hd;
  9413. var cs = hd.parentNode.childNodes;
  9414. for(var i = 0, c; c = cs[i]; i++){
  9415. if(c == hd){
  9416. return i;
  9417. }
  9418. }
  9419. return -1;
  9420. },
  9421. // private
  9422. beforeColMenuShow : function(){
  9423. var cols = this.columns,
  9424. colCount = cols.length,
  9425. i, c;
  9426. this.colMenu.removeAll();
  9427. for(i = 1; i < colCount; i++){
  9428. c = cols[i];
  9429. if(c.hideable !== false){
  9430. this.colMenu.add(new Ext.menu.CheckItem({
  9431. itemId: 'col-' + i,
  9432. text: c.header,
  9433. checked: !c.hidden,
  9434. hideOnClick:false,
  9435. disabled: c.hideable === false
  9436. }));
  9437. }
  9438. }
  9439. },
  9440. // private
  9441. handleHdMenuClick : function(item){
  9442. var index = this.hdCtxIndex,
  9443. id = item.getItemId();
  9444. if(this.fireEvent('headermenuclick', this.columns[index], id, index) !== false) {
  9445. index = id.substr(4);
  9446. if(index > 0 && this.columns[index]) {
  9447. this.setColumnVisible(index, !item.checked);
  9448. }
  9449. }
  9450. return true;
  9451. },
  9452. setColumnVisible : function(index, visible) {
  9453. this.columns[index].hidden = !visible;
  9454. this.updateColumnWidths();
  9455. },
  9456. /**
  9457. * Scrolls the grid to the top
  9458. */
  9459. scrollToTop : function(){
  9460. this.innerBody.dom.scrollTop = 0;
  9461. this.innerBody.dom.scrollLeft = 0;
  9462. },
  9463. // private
  9464. syncScroll : function(){
  9465. this.syncHeaderScroll();
  9466. var mb = this.innerBody.dom;
  9467. this.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
  9468. },
  9469. // private
  9470. syncHeaderScroll : function(){
  9471. var mb = this.innerBody.dom;
  9472. this.innerHd.dom.scrollLeft = mb.scrollLeft;
  9473. this.innerHd.dom.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
  9474. },
  9475. registerNode : function(n) {
  9476. Ext.ux.tree.TreeGrid.superclass.registerNode.call(this, n);
  9477. if(!n.uiProvider && !n.isRoot && !n.ui.isTreeGridNodeUI) {
  9478. n.ui = new Ext.ux.tree.TreeGridNodeUI(n);
  9479. }
  9480. }
  9481. });
  9482. Ext.reg('treegrid', Ext.ux.tree.TreeGrid);