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.

10625 lines
340 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.ns('Ext.ux.grid');
  16. /**
  17. * @class Ext.ux.grid.BufferView
  18. * @extends Ext.grid.GridView
  19. * A custom GridView which renders rows on an as-needed basis.
  20. */
  21. Ext.ux.grid.BufferView = Ext.extend(Ext.grid.GridView, {
  22. /**
  23. * @cfg {Number} rowHeight
  24. * The height of a row in the grid.
  25. */
  26. rowHeight: 19,
  27. /**
  28. * @cfg {Number} borderHeight
  29. * The combined height of border-top and border-bottom of a row.
  30. */
  31. borderHeight: 2,
  32. /**
  33. * @cfg {Boolean/Number} scrollDelay
  34. * The number of milliseconds before rendering rows out of the visible
  35. * viewing area. Defaults to 100. Rows will render immediately with a config
  36. * of false.
  37. */
  38. scrollDelay: 100,
  39. /**
  40. * @cfg {Number} cacheSize
  41. * The number of rows to look forward and backwards from the currently viewable
  42. * area. The cache applies only to rows that have been rendered already.
  43. */
  44. cacheSize: 20,
  45. /**
  46. * @cfg {Number} cleanDelay
  47. * The number of milliseconds to buffer cleaning of extra rows not in the
  48. * cache.
  49. */
  50. cleanDelay: 500,
  51. initTemplates : function(){
  52. Ext.ux.grid.BufferView.superclass.initTemplates.call(this);
  53. var ts = this.templates;
  54. // empty div to act as a place holder for a row
  55. ts.rowHolder = new Ext.Template(
  56. '<div class="x-grid3-row {alt}" style="{tstyle}"></div>'
  57. );
  58. ts.rowHolder.disableFormats = true;
  59. ts.rowHolder.compile();
  60. ts.rowBody = new Ext.Template(
  61. '<table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
  62. '<tbody><tr>{cells}</tr>',
  63. (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>' : ''),
  64. '</tbody></table>'
  65. );
  66. ts.rowBody.disableFormats = true;
  67. ts.rowBody.compile();
  68. },
  69. getStyleRowHeight : function(){
  70. return Ext.isBorderBox ? (this.rowHeight + this.borderHeight) : this.rowHeight;
  71. },
  72. getCalculatedRowHeight : function(){
  73. return this.rowHeight + this.borderHeight;
  74. },
  75. getVisibleRowCount : function(){
  76. var rh = this.getCalculatedRowHeight(),
  77. visibleHeight = this.scroller.dom.clientHeight;
  78. return (visibleHeight < 1) ? 0 : Math.ceil(visibleHeight / rh);
  79. },
  80. getVisibleRows: function(){
  81. var count = this.getVisibleRowCount(),
  82. sc = this.scroller.dom.scrollTop,
  83. start = (sc === 0 ? 0 : Math.floor(sc/this.getCalculatedRowHeight())-1);
  84. return {
  85. first: Math.max(start, 0),
  86. last: Math.min(start + count + 2, this.ds.getCount()-1)
  87. };
  88. },
  89. doRender : function(cs, rs, ds, startRow, colCount, stripe, onlyBody){
  90. var ts = this.templates,
  91. ct = ts.cell,
  92. rt = ts.row,
  93. rb = ts.rowBody,
  94. last = colCount-1,
  95. rh = this.getStyleRowHeight(),
  96. vr = this.getVisibleRows(),
  97. tstyle = 'width:'+this.getTotalWidth()+';height:'+rh+'px;',
  98. // buffers
  99. buf = [],
  100. cb,
  101. c,
  102. p = {},
  103. rp = {tstyle: tstyle},
  104. r;
  105. for (var j = 0, len = rs.length; j < len; j++) {
  106. r = rs[j]; cb = [];
  107. var rowIndex = (j+startRow),
  108. visible = rowIndex >= vr.first && rowIndex <= vr.last;
  109. if (visible) {
  110. for (var i = 0; i < colCount; i++) {
  111. c = cs[i];
  112. p.id = c.id;
  113. p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
  114. p.attr = p.cellAttr = "";
  115. p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
  116. p.style = c.style;
  117. if (p.value === undefined || p.value === "") {
  118. p.value = "&#160;";
  119. }
  120. if (r.dirty && typeof r.modified[c.name] !== 'undefined') {
  121. p.css += ' x-grid3-dirty-cell';
  122. }
  123. cb[cb.length] = ct.apply(p);
  124. }
  125. }
  126. var alt = [];
  127. if(stripe && ((rowIndex+1) % 2 === 0)){
  128. alt[0] = "x-grid3-row-alt";
  129. }
  130. if(r.dirty){
  131. alt[1] = " x-grid3-dirty-row";
  132. }
  133. rp.cols = colCount;
  134. if(this.getRowClass){
  135. alt[2] = this.getRowClass(r, rowIndex, rp, ds);
  136. }
  137. rp.alt = alt.join(" ");
  138. rp.cells = cb.join("");
  139. buf[buf.length] = !visible ? ts.rowHolder.apply(rp) : (onlyBody ? rb.apply(rp) : rt.apply(rp));
  140. }
  141. return buf.join("");
  142. },
  143. isRowRendered: function(index){
  144. var row = this.getRow(index);
  145. return row && row.childNodes.length > 0;
  146. },
  147. syncScroll: function(){
  148. Ext.ux.grid.BufferView.superclass.syncScroll.apply(this, arguments);
  149. this.update();
  150. },
  151. // a (optionally) buffered method to update contents of gridview
  152. update: function(){
  153. if (this.scrollDelay) {
  154. if (!this.renderTask) {
  155. this.renderTask = new Ext.util.DelayedTask(this.doUpdate, this);
  156. }
  157. this.renderTask.delay(this.scrollDelay);
  158. }else{
  159. this.doUpdate();
  160. }
  161. },
  162. onRemove : function(ds, record, index, isUpdate){
  163. Ext.ux.grid.BufferView.superclass.onRemove.apply(this, arguments);
  164. if(isUpdate !== true){
  165. this.update();
  166. }
  167. },
  168. doUpdate: function(){
  169. if (this.getVisibleRowCount() > 0) {
  170. var g = this.grid,
  171. cm = g.colModel,
  172. ds = g.store,
  173. cs = this.getColumnData(),
  174. vr = this.getVisibleRows(),
  175. row;
  176. for (var i = vr.first; i <= vr.last; i++) {
  177. // if row is NOT rendered and is visible, render it
  178. if(!this.isRowRendered(i) && (row = this.getRow(i))){
  179. var html = this.doRender(cs, [ds.getAt(i)], ds, i, cm.getColumnCount(), g.stripeRows, true);
  180. row.innerHTML = html;
  181. }
  182. }
  183. this.clean();
  184. }
  185. },
  186. // a buffered method to clean rows
  187. clean : function(){
  188. if(!this.cleanTask){
  189. this.cleanTask = new Ext.util.DelayedTask(this.doClean, this);
  190. }
  191. this.cleanTask.delay(this.cleanDelay);
  192. },
  193. doClean: function(){
  194. if (this.getVisibleRowCount() > 0) {
  195. var vr = this.getVisibleRows();
  196. vr.first -= this.cacheSize;
  197. vr.last += this.cacheSize;
  198. var i = 0, rows = this.getRows();
  199. // if first is less than 0, all rows have been rendered
  200. // so lets clean the end...
  201. if(vr.first <= 0){
  202. i = vr.last + 1;
  203. }
  204. for(var len = this.ds.getCount(); i < len; i++){
  205. // if current row is outside of first and last and
  206. // has content, update the innerHTML to nothing
  207. if ((i < vr.first || i > vr.last) && rows[i].innerHTML) {
  208. rows[i].innerHTML = '';
  209. }
  210. }
  211. }
  212. },
  213. removeTask: function(name){
  214. var task = this[name];
  215. if(task && task.cancel){
  216. task.cancel();
  217. this[name] = null;
  218. }
  219. },
  220. destroy : function(){
  221. this.removeTask('cleanTask');
  222. this.removeTask('renderTask');
  223. Ext.ux.grid.BufferView.superclass.destroy.call(this);
  224. },
  225. layout: function(){
  226. Ext.ux.grid.BufferView.superclass.layout.call(this);
  227. this.update();
  228. }
  229. });// We are adding these custom layouts to a namespace that does not
  230. // exist by default in Ext, so we have to add the namespace first:
  231. Ext.ns('Ext.ux.layout');
  232. /**
  233. * @class Ext.ux.layout.CenterLayout
  234. * @extends Ext.layout.FitLayout
  235. * <p>This is a very simple layout style used to center contents within a container. This layout works within
  236. * nested containers and can also be used as expected as a Viewport layout to center the page layout.</p>
  237. * <p>As a subclass of FitLayout, CenterLayout expects to have a single child panel of the container that uses
  238. * the layout. The layout does not require any config options, although the child panel contained within the
  239. * layout must provide a fixed or percentage width. The child panel's height will fit to the container by
  240. * default, but you can specify <tt>autoHeight:true</tt> to allow it to autosize based on its content height.
  241. * Example usage:</p>
  242. * <pre><code>
  243. // The content panel is centered in the container
  244. var p = new Ext.Panel({
  245. title: 'Center Layout',
  246. layout: 'ux.center',
  247. items: [{
  248. title: 'Centered Content',
  249. width: '75%',
  250. html: 'Some content'
  251. }]
  252. });
  253. // If you leave the title blank and specify no border
  254. // you'll create a non-visual, structural panel just
  255. // for centering the contents in the main container.
  256. var p = new Ext.Panel({
  257. layout: 'ux.center',
  258. border: false,
  259. items: [{
  260. title: 'Centered Content',
  261. width: 300,
  262. autoHeight: true,
  263. html: 'Some content'
  264. }]
  265. });
  266. </code></pre>
  267. */
  268. Ext.ux.layout.CenterLayout = Ext.extend(Ext.layout.FitLayout, {
  269. // private
  270. setItemSize : function(item, size){
  271. this.container.addClass('ux-layout-center');
  272. item.addClass('ux-layout-center-item');
  273. if(item && size.height > 0){
  274. if(item.width){
  275. size.width = item.width;
  276. }
  277. item.setSize(size);
  278. }
  279. }
  280. });
  281. Ext.Container.LAYOUTS['ux.center'] = Ext.ux.layout.CenterLayout;
  282. Ext.ns('Ext.ux.grid');
  283. /**
  284. * @class Ext.ux.grid.CheckColumn
  285. * @extends Ext.grid.Column
  286. * <p>A Column subclass which renders a checkbox in each column cell which toggles the truthiness of the associated data field on click.</p>
  287. * <p><b>Note. As of ExtJS 3.3 this no longer has to be configured as a plugin of the GridPanel.</b></p>
  288. * <p>Example usage:</p>
  289. * <pre><code>
  290. var cm = new Ext.grid.ColumnModel([{
  291. header: 'Foo',
  292. ...
  293. },{
  294. xtype: 'checkcolumn',
  295. header: 'Indoor?',
  296. dataIndex: 'indoor',
  297. width: 55
  298. }
  299. ]);
  300. // create the grid
  301. var grid = new Ext.grid.EditorGridPanel({
  302. ...
  303. colModel: cm,
  304. ...
  305. });
  306. * </code></pre>
  307. * In addition to toggling a Boolean value within the record data, this
  308. * class toggles a css class between <tt>'x-grid3-check-col'</tt> and
  309. * <tt>'x-grid3-check-col-on'</tt> to alter the background image used for
  310. * a column.
  311. */
  312. Ext.ux.grid.CheckColumn = Ext.extend(Ext.grid.Column, {
  313. /**
  314. * @private
  315. * Process and refire events routed from the GridView's processEvent method.
  316. */
  317. processEvent : function(name, e, grid, rowIndex, colIndex){
  318. if (name == 'mousedown') {
  319. var record = grid.store.getAt(rowIndex);
  320. record.set(this.dataIndex, !record.data[this.dataIndex]);
  321. return false; // Cancel row selection.
  322. } else {
  323. return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments);
  324. }
  325. },
  326. renderer : function(v, p, record){
  327. p.css += ' x-grid3-check-col-td';
  328. return String.format('<div class="x-grid3-check-col{0}">&#160;</div>', v ? '-on' : '');
  329. },
  330. // Deprecate use as a plugin. Remove in 4.0
  331. init: Ext.emptyFn
  332. });
  333. // register ptype. Deprecate. Remove in 4.0
  334. Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn);
  335. // backwards compat. Remove in 4.0
  336. Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn;
  337. // register Column xtype
  338. Ext.grid.Column.types.checkcolumn = Ext.ux.grid.CheckColumn;Ext.ns('Ext.ux.grid');
  339. Ext.ux.grid.ColumnHeaderGroup = Ext.extend(Ext.util.Observable, {
  340. constructor: function(config){
  341. this.config = config;
  342. },
  343. init: function(grid){
  344. Ext.applyIf(grid.colModel, this.config);
  345. Ext.apply(grid.getView(), this.viewConfig);
  346. },
  347. viewConfig: {
  348. initTemplates: function(){
  349. this.constructor.prototype.initTemplates.apply(this, arguments);
  350. var ts = this.templates || {};
  351. if(!ts.gcell){
  352. 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>');
  353. }
  354. this.templates = ts;
  355. this.hrowRe = new RegExp("ux-grid-hd-group-row-(\\d+)", "");
  356. },
  357. renderHeaders: function(){
  358. var ts = this.templates, headers = [], cm = this.cm, rows = cm.rows, tstyle = 'width:' + this.getTotalWidth() + ';';
  359. for(var row = 0, rlen = rows.length; row < rlen; row++){
  360. var r = rows[row], cells = [];
  361. for(var i = 0, gcol = 0, len = r.length; i < len; i++){
  362. var group = r[i];
  363. group.colspan = group.colspan || 1;
  364. var id = this.getColumnId(group.dataIndex ? cm.findColumnIndex(group.dataIndex) : gcol), gs = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupStyle.call(this, group, gcol);
  365. cells[i] = ts.gcell.apply({
  366. cls: 'ux-grid-hd-group-cell',
  367. id: id,
  368. row: row,
  369. style: 'width:' + gs.width + ';' + (gs.hidden ? 'display:none;' : '') + (group.align ? 'text-align:' + group.align + ';' : ''),
  370. tooltip: group.tooltip ? (Ext.QuickTips.isEnabled() ? 'ext:qtip' : 'title') + '="' + group.tooltip + '"' : '',
  371. istyle: group.align == 'right' ? 'padding-right:16px' : '',
  372. btn: this.grid.enableHdMenu && group.header,
  373. value: group.header || '&nbsp;'
  374. });
  375. gcol += group.colspan;
  376. }
  377. headers[row] = ts.header.apply({
  378. tstyle: tstyle,
  379. cells: cells.join('')
  380. });
  381. }
  382. headers.push(this.constructor.prototype.renderHeaders.apply(this, arguments));
  383. return headers.join('');
  384. },
  385. onColumnWidthUpdated: function(){
  386. this.constructor.prototype.onColumnWidthUpdated.apply(this, arguments);
  387. Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
  388. },
  389. onAllColumnWidthsUpdated: function(){
  390. this.constructor.prototype.onAllColumnWidthsUpdated.apply(this, arguments);
  391. Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
  392. },
  393. onColumnHiddenUpdated: function(){
  394. this.constructor.prototype.onColumnHiddenUpdated.apply(this, arguments);
  395. Ext.ux.grid.ColumnHeaderGroup.prototype.updateGroupStyles.call(this);
  396. },
  397. getHeaderCell: function(index){
  398. return this.mainHd.query(this.cellSelector)[index];
  399. },
  400. findHeaderCell: function(el){
  401. return el ? this.fly(el).findParent('td.x-grid3-hd', this.cellSelectorDepth) : false;
  402. },
  403. findHeaderIndex: function(el){
  404. var cell = this.findHeaderCell(el);
  405. return cell ? this.getCellIndex(cell) : false;
  406. },
  407. updateSortIcon: function(col, dir){
  408. var sc = this.sortClasses, hds = this.mainHd.select(this.cellSelector).removeClass(sc);
  409. hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
  410. },
  411. handleHdDown: function(e, t){
  412. var el = Ext.get(t);
  413. if(el.hasClass('x-grid3-hd-btn')){
  414. e.stopEvent();
  415. var hd = this.findHeaderCell(t);
  416. Ext.fly(hd).addClass('x-grid3-hd-menu-open');
  417. var index = this.getCellIndex(hd);
  418. this.hdCtxIndex = index;
  419. var ms = this.hmenu.items, cm = this.cm;
  420. ms.get('asc').setDisabled(!cm.isSortable(index));
  421. ms.get('desc').setDisabled(!cm.isSortable(index));
  422. this.hmenu.on('hide', function(){
  423. Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
  424. }, this, {
  425. single: true
  426. });
  427. this.hmenu.show(t, 'tl-bl?');
  428. }else if(el.hasClass('ux-grid-hd-group-cell') || Ext.fly(t).up('.ux-grid-hd-group-cell')){
  429. e.stopEvent();
  430. }
  431. },
  432. handleHdMove: function(e, t){
  433. var hd = this.findHeaderCell(this.activeHdRef);
  434. if(hd && !this.headersDisabled && !Ext.fly(hd).hasClass('ux-grid-hd-group-cell')){
  435. var hw = this.splitHandleWidth || 5, r = this.activeHdRegion, x = e.getPageX(), ss = hd.style, cur = '';
  436. if(this.grid.enableColumnResize !== false){
  437. if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex - 1)){
  438. cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize
  439. // not
  440. // always
  441. // supported
  442. }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
  443. cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize';
  444. }
  445. }
  446. ss.cursor = cur;
  447. }
  448. },
  449. handleHdOver: function(e, t){
  450. var hd = this.findHeaderCell(t);
  451. if(hd && !this.headersDisabled){
  452. this.activeHdRef = t;
  453. this.activeHdIndex = this.getCellIndex(hd);
  454. var fly = this.fly(hd);
  455. this.activeHdRegion = fly.getRegion();
  456. if(!(this.cm.isMenuDisabled(this.activeHdIndex) || fly.hasClass('ux-grid-hd-group-cell'))){
  457. fly.addClass('x-grid3-hd-over');
  458. this.activeHdBtn = fly.child('.x-grid3-hd-btn');
  459. if(this.activeHdBtn){
  460. this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight - 1) + 'px';
  461. }
  462. }
  463. }
  464. },
  465. handleHdOut: function(e, t){
  466. var hd = this.findHeaderCell(t);
  467. if(hd && (!Ext.isIE || !e.within(hd, true))){
  468. this.activeHdRef = null;
  469. this.fly(hd).removeClass('x-grid3-hd-over');
  470. hd.style.cursor = '';
  471. }
  472. },
  473. handleHdMenuClick: function(item){
  474. var index = this.hdCtxIndex, cm = this.cm, ds = this.ds, id = item.getItemId();
  475. switch(id){
  476. case 'asc':
  477. ds.sort(cm.getDataIndex(index), 'ASC');
  478. break;
  479. case 'desc':
  480. ds.sort(cm.getDataIndex(index), 'DESC');
  481. break;
  482. default:
  483. if(id.substr(0, 6) == 'group-'){
  484. var i = id.split('-'), row = parseInt(i[1], 10), col = parseInt(i[2], 10), r = this.cm.rows[row], group, gcol = 0;
  485. for(var i = 0, len = r.length; i < len; i++){
  486. group = r[i];
  487. if(col >= gcol && col < gcol + group.colspan){
  488. break;
  489. }
  490. gcol += group.colspan;
  491. }
  492. if(item.checked){
  493. var max = cm.getColumnsBy(this.isHideableColumn, this).length;
  494. for(var i = gcol, len = gcol + group.colspan; i < len; i++){
  495. if(!cm.isHidden(i)){
  496. max--;
  497. }
  498. }
  499. if(max < 1){
  500. this.onDenyColumnHide();
  501. return false;
  502. }
  503. }
  504. for(var i = gcol, len = gcol + group.colspan; i < len; i++){
  505. if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
  506. cm.setHidden(i, item.checked);
  507. }
  508. }
  509. }else if(id.substr(0, 4) == 'col-'){
  510. index = cm.getIndexById(id.substr(4));
  511. if(index != -1){
  512. if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
  513. this.onDenyColumnHide();
  514. return false;
  515. }
  516. cm.setHidden(index, item.checked);
  517. }
  518. }
  519. if(id.substr(0, 6) == 'group-' || id.substr(0, 4) == 'col-'){
  520. item.checked = !item.checked;
  521. if(item.menu){
  522. var updateChildren = function(menu){
  523. menu.items.each(function(childItem){
  524. if(!childItem.disabled){
  525. childItem.setChecked(item.checked, false);
  526. if(childItem.menu){
  527. updateChildren(childItem.menu);
  528. }
  529. }
  530. });
  531. }
  532. updateChildren(item.menu);
  533. }
  534. var parentMenu = item, parentItem;
  535. while(parentMenu = parentMenu.parentMenu){
  536. if(!parentMenu.parentMenu || !(parentItem = parentMenu.parentMenu.items.get(parentMenu.getItemId())) || !parentItem.setChecked){
  537. break;
  538. }
  539. var checked = parentMenu.items.findIndexBy(function(m){
  540. return m.checked;
  541. }) >= 0;
  542. parentItem.setChecked(checked, true);
  543. }
  544. item.checked = !item.checked;
  545. }
  546. }
  547. return true;
  548. },
  549. beforeColMenuShow: function(){
  550. var cm = this.cm, rows = this.cm.rows;
  551. this.colMenu.removeAll();
  552. for(var col = 0, clen = cm.getColumnCount(); col < clen; col++){
  553. var menu = this.colMenu, title = cm.getColumnHeader(col), text = [];
  554. if(cm.config[col].fixed !== true && cm.config[col].hideable !== false){
  555. for(var row = 0, rlen = rows.length; row < rlen; row++){
  556. var r = rows[row], group, gcol = 0;
  557. for(var i = 0, len = r.length; i < len; i++){
  558. group = r[i];
  559. if(col >= gcol && col < gcol + group.colspan){
  560. break;
  561. }
  562. gcol += group.colspan;
  563. }
  564. if(group && group.header){
  565. if(cm.hierarchicalColMenu){
  566. var gid = 'group-' + row + '-' + gcol,
  567. item = menu.items ? menu.getComponent(gid) : null,
  568. submenu = item ? item.menu : null;
  569. if(!submenu){
  570. submenu = new Ext.menu.Menu({
  571. itemId: gid
  572. });
  573. submenu.on("itemclick", this.handleHdMenuClick, this);
  574. var checked = false, disabled = true;
  575. for(var c = gcol, lc = gcol + group.colspan; c < lc; c++){
  576. if(!cm.isHidden(c)){
  577. checked = true;
  578. }
  579. if(cm.config[c].hideable !== false){
  580. disabled = false;
  581. }
  582. }
  583. menu.add({
  584. itemId: gid,
  585. text: group.header,
  586. menu: submenu,
  587. hideOnClick: false,
  588. checked: checked,
  589. disabled: disabled
  590. });
  591. }
  592. menu = submenu;
  593. }else{
  594. text.push(group.header);
  595. }
  596. }
  597. }
  598. text.push(title);
  599. menu.add(new Ext.menu.CheckItem({
  600. itemId: "col-" + cm.getColumnId(col),
  601. text: text.join(' '),
  602. checked: !cm.isHidden(col),
  603. hideOnClick: false,
  604. disabled: cm.config[col].hideable === false
  605. }));
  606. }
  607. }
  608. },
  609. afterRenderUI: function(){
  610. this.constructor.prototype.afterRenderUI.apply(this, arguments);
  611. Ext.apply(this.columnDrop, Ext.ux.grid.ColumnHeaderGroup.prototype.columnDropConfig);
  612. Ext.apply(this.splitZone, Ext.ux.grid.ColumnHeaderGroup.prototype.splitZoneConfig);
  613. }
  614. },
  615. splitZoneConfig: {
  616. allowHeaderDrag: function(e){
  617. return !e.getTarget(null, null, true).hasClass('ux-grid-hd-group-cell');
  618. }
  619. },
  620. columnDropConfig: {
  621. getTargetFromEvent: function(e){
  622. var t = Ext.lib.Event.getTarget(e);
  623. return this.view.findHeaderCell(t);
  624. },
  625. positionIndicator: function(h, n, e){
  626. var data = Ext.ux.grid.ColumnHeaderGroup.prototype.getDragDropData.call(this, h, n, e);
  627. if(data === false){
  628. return false;
  629. }
  630. var px = data.px + this.proxyOffsets[0];
  631. this.proxyTop.setLeftTop(px, data.r.top + this.proxyOffsets[1]);
  632. this.proxyTop.show();
  633. this.proxyBottom.setLeftTop(px, data.r.bottom);
  634. this.proxyBottom.show();
  635. return data.pt;
  636. },
  637. onNodeDrop: function(n, dd, e, data){
  638. var h = data.header;
  639. if(h != n){
  640. var d = Ext.ux.grid.ColumnHeaderGroup.prototype.getDragDropData.call(this, h, n, e);
  641. if(d === false){
  642. return false;
  643. }
  644. var cm = this.grid.colModel, right = d.oldIndex < d.newIndex, rows = cm.rows;
  645. for(var row = d.row, rlen = rows.length; row < rlen; row++){
  646. var r = rows[row], len = r.length, fromIx = 0, span = 1, toIx = len;
  647. for(var i = 0, gcol = 0; i < len; i++){
  648. var group = r[i];
  649. if(d.oldIndex >= gcol && d.oldIndex < gcol + group.colspan){
  650. fromIx = i;
  651. }
  652. if(d.oldIndex + d.colspan - 1 >= gcol && d.oldIndex + d.colspan - 1 < gcol + group.colspan){
  653. span = i - fromIx + 1;
  654. }
  655. if(d.newIndex >= gcol && d.newIndex < gcol + group.colspan){
  656. toIx = i;
  657. }
  658. gcol += group.colspan;
  659. }
  660. var groups = r.splice(fromIx, span);
  661. rows[row] = r.splice(0, toIx - (right ? span : 0)).concat(groups).concat(r);
  662. }
  663. for(var c = 0; c < d.colspan; c++){
  664. var oldIx = d.oldIndex + (right ? 0 : c), newIx = d.newIndex + (right ? -1 : c);
  665. cm.moveColumn(oldIx, newIx);
  666. this.grid.fireEvent("columnmove", oldIx, newIx);
  667. }
  668. return true;
  669. }
  670. return false;
  671. }
  672. },
  673. getGroupStyle: function(group, gcol){
  674. var width = 0, hidden = true;
  675. for(var i = gcol, len = gcol + group.colspan; i < len; i++){
  676. if(!this.cm.isHidden(i)){
  677. var cw = this.cm.getColumnWidth(i);
  678. if(typeof cw == 'number'){
  679. width += cw;
  680. }
  681. hidden = false;
  682. }
  683. }
  684. return {
  685. width: (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? width : Math.max(width - this.borderWidth, 0)) + 'px',
  686. hidden: hidden
  687. };
  688. },
  689. updateGroupStyles: function(col){
  690. var tables = this.mainHd.query('.x-grid3-header-offset > table'), tw = this.getTotalWidth(), rows = this.cm.rows;
  691. for(var row = 0; row < tables.length; row++){
  692. tables[row].style.width = tw;
  693. if(row < rows.length){
  694. var cells = tables[row].firstChild.firstChild.childNodes;
  695. for(var i = 0, gcol = 0; i < cells.length; i++){
  696. var group = rows[row][i];
  697. if((typeof col != 'number') || (col >= gcol && col < gcol + group.colspan)){
  698. var gs = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupStyle.call(this, group, gcol);
  699. cells[i].style.width = gs.width;
  700. cells[i].style.display = gs.hidden ? 'none' : '';
  701. }
  702. gcol += group.colspan;
  703. }
  704. }
  705. }
  706. },
  707. getGroupRowIndex: function(el){
  708. if(el){
  709. var m = el.className.match(this.hrowRe);
  710. if(m && m[1]){
  711. return parseInt(m[1], 10);
  712. }
  713. }
  714. return this.cm.rows.length;
  715. },
  716. getGroupSpan: function(row, col){
  717. if(row < 0){
  718. return {
  719. col: 0,
  720. colspan: this.cm.getColumnCount()
  721. };
  722. }
  723. var r = this.cm.rows[row];
  724. if(r){
  725. for(var i = 0, gcol = 0, len = r.length; i < len; i++){
  726. var group = r[i];
  727. if(col >= gcol && col < gcol + group.colspan){
  728. return {
  729. col: gcol,
  730. colspan: group.colspan
  731. };
  732. }
  733. gcol += group.colspan;
  734. }
  735. return {
  736. col: gcol,
  737. colspan: 0
  738. };
  739. }
  740. return {
  741. col: col,
  742. colspan: 1
  743. };
  744. },
  745. getDragDropData: function(h, n, e){
  746. if(h.parentNode != n.parentNode){
  747. return false;
  748. }
  749. var cm = this.grid.colModel, x = Ext.lib.Event.getPageX(e), r = Ext.lib.Dom.getRegion(n.firstChild), px, pt;
  750. if((r.right - x) <= (r.right - r.left) / 2){
  751. px = r.right + this.view.borderWidth;
  752. pt = "after";
  753. }else{
  754. px = r.left;
  755. pt = "before";
  756. }
  757. var oldIndex = this.view.getCellIndex(h), newIndex = this.view.getCellIndex(n);
  758. if(cm.isFixed(newIndex)){
  759. return false;
  760. }
  761. var row = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupRowIndex.call(this.view, h),
  762. oldGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row, oldIndex),
  763. newGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row, newIndex),
  764. oldIndex = oldGroup.col;
  765. newIndex = newGroup.col + (pt == "after" ? newGroup.colspan : 0);
  766. if(newIndex >= oldGroup.col && newIndex <= oldGroup.col + oldGroup.colspan){
  767. return false;
  768. }
  769. var parentGroup = Ext.ux.grid.ColumnHeaderGroup.prototype.getGroupSpan.call(this.view, row - 1, oldIndex);
  770. if(newIndex < parentGroup.col || newIndex > parentGroup.col + parentGroup.colspan){
  771. return false;
  772. }
  773. return {
  774. r: r,
  775. px: px,
  776. pt: pt,
  777. row: row,
  778. oldIndex: oldIndex,
  779. newIndex: newIndex,
  780. colspan: oldGroup.colspan
  781. };
  782. }
  783. });Ext.ns('Ext.ux.tree');
  784. /**
  785. * @class Ext.ux.tree.ColumnTree
  786. * @extends Ext.tree.TreePanel
  787. *
  788. * @xtype columntree
  789. */
  790. Ext.ux.tree.ColumnTree = Ext.extend(Ext.tree.TreePanel, {
  791. lines : false,
  792. borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
  793. cls : 'x-column-tree',
  794. onRender : function(){
  795. Ext.tree.ColumnTree.superclass.onRender.apply(this, arguments);
  796. this.headers = this.header.createChild({cls:'x-tree-headers'});
  797. var cols = this.columns, c;
  798. var totalWidth = 0;
  799. var scrollOffset = 19; // similar to Ext.grid.GridView default
  800. for(var i = 0, len = cols.length; i < len; i++){
  801. c = cols[i];
  802. totalWidth += c.width;
  803. this.headers.createChild({
  804. cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
  805. cn: {
  806. cls:'x-tree-hd-text',
  807. html: c.header
  808. },
  809. style:'width:'+(c.width-this.borderWidth)+'px;'
  810. });
  811. }
  812. this.headers.createChild({cls:'x-clear'});
  813. // prevent floats from wrapping when clipped
  814. this.headers.setWidth(totalWidth+scrollOffset);
  815. this.innerCt.setWidth(totalWidth);
  816. }
  817. });
  818. Ext.reg('columntree', Ext.ux.tree.ColumnTree);
  819. //backwards compat
  820. Ext.tree.ColumnTree = Ext.ux.tree.ColumnTree;
  821. /**
  822. * @class Ext.ux.tree.ColumnNodeUI
  823. * @extends Ext.tree.TreeNodeUI
  824. */
  825. Ext.ux.tree.ColumnNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  826. focus: Ext.emptyFn, // prevent odd scrolling behavior
  827. renderElements : function(n, a, targetNode, bulkRender){
  828. this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
  829. var t = n.getOwnerTree();
  830. var cols = t.columns;
  831. var bw = t.borderWidth;
  832. var c = cols[0];
  833. var buf = [
  834. '<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf ', a.cls,'">',
  835. '<div class="x-tree-col" style="width:',c.width-bw,'px;">',
  836. '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
  837. '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow">',
  838. '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on">',
  839. '<a hidefocus="on" class="x-tree-node-anchor" href="',a.href ? a.href : "#",'" tabIndex="1" ',
  840. a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '>',
  841. '<span unselectable="on">', n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</span></a>",
  842. "</div>"];
  843. for(var i = 1, len = cols.length; i < len; i++){
  844. c = cols[i];
  845. buf.push('<div class="x-tree-col ',(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
  846. '<div class="x-tree-col-text">',(c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]),"</div>",
  847. "</div>");
  848. }
  849. buf.push(
  850. '<div class="x-clear"></div></div>',
  851. '<ul class="x-tree-node-ct" style="display:none;"></ul>',
  852. "</li>");
  853. if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
  854. this.wrap = Ext.DomHelper.insertHtml("beforeBegin",
  855. n.nextSibling.ui.getEl(), buf.join(""));
  856. }else{
  857. this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
  858. }
  859. this.elNode = this.wrap.childNodes[0];
  860. this.ctNode = this.wrap.childNodes[1];
  861. var cs = this.elNode.firstChild.childNodes;
  862. this.indentNode = cs[0];
  863. this.ecNode = cs[1];
  864. this.iconNode = cs[2];
  865. this.anchor = cs[3];
  866. this.textNode = cs[3].firstChild;
  867. }
  868. });
  869. //backwards compat
  870. Ext.tree.ColumnNodeUI = Ext.ux.tree.ColumnNodeUI;
  871. /**
  872. * @class Ext.DataView.LabelEditor
  873. * @extends Ext.Editor
  874. *
  875. */
  876. Ext.DataView.LabelEditor = Ext.extend(Ext.Editor, {
  877. alignment: "tl-tl",
  878. hideEl : false,
  879. cls: "x-small-editor",
  880. shim: false,
  881. completeOnEnter: true,
  882. cancelOnEsc: true,
  883. labelSelector: 'span.x-editable',
  884. constructor: function(cfg, field){
  885. Ext.DataView.LabelEditor.superclass.constructor.call(this,
  886. field || new Ext.form.TextField({
  887. allowBlank: false,
  888. growMin:90,
  889. growMax:240,
  890. grow:true,
  891. selectOnFocus:true
  892. }), cfg
  893. );
  894. },
  895. init : function(view){
  896. this.view = view;
  897. view.on('render', this.initEditor, this);
  898. this.on('complete', this.onSave, this);
  899. },
  900. initEditor : function(){
  901. this.view.on({
  902. scope: this,
  903. containerclick: this.doBlur,
  904. click: this.doBlur
  905. });
  906. this.view.getEl().on('mousedown', this.onMouseDown, this, {delegate: this.labelSelector});
  907. },
  908. doBlur: function(){
  909. if(this.editing){
  910. this.field.blur();
  911. }
  912. },
  913. onMouseDown : function(e, target){
  914. if(!e.ctrlKey && !e.shiftKey){
  915. var item = this.view.findItemFromChild(target);
  916. e.stopEvent();
  917. var record = this.view.store.getAt(this.view.indexOf(item));
  918. this.startEdit(target, record.data[this.dataIndex]);
  919. this.activeRecord = record;
  920. }else{
  921. e.preventDefault();
  922. }
  923. },
  924. onSave : function(ed, value){
  925. this.activeRecord.set(this.dataIndex, value);
  926. }
  927. });
  928. Ext.DataView.DragSelector = function(cfg){
  929. cfg = cfg || {};
  930. var view, proxy, tracker;
  931. var rs, bodyRegion, dragRegion = new Ext.lib.Region(0,0,0,0);
  932. var dragSafe = cfg.dragSafe === true;
  933. this.init = function(dataView){
  934. view = dataView;
  935. view.on('render', onRender);
  936. };
  937. function fillRegions(){
  938. rs = [];
  939. view.all.each(function(el){
  940. rs[rs.length] = el.getRegion();
  941. });
  942. bodyRegion = view.el.getRegion();
  943. }
  944. function cancelClick(){
  945. return false;
  946. }
  947. function onBeforeStart(e){
  948. return !dragSafe || e.target == view.el.dom;
  949. }
  950. function onStart(e){
  951. view.on('containerclick', cancelClick, view, {single:true});
  952. if(!proxy){
  953. proxy = view.el.createChild({cls:'x-view-selector'});
  954. }else{
  955. if(proxy.dom.parentNode !== view.el.dom){
  956. view.el.dom.appendChild(proxy.dom);
  957. }
  958. proxy.setDisplayed('block');
  959. }
  960. fillRegions();
  961. view.clearSelections();
  962. }
  963. function onDrag(e){
  964. var startXY = tracker.startXY;
  965. var xy = tracker.getXY();
  966. var x = Math.min(startXY[0], xy[0]);
  967. var y = Math.min(startXY[1], xy[1]);
  968. var w = Math.abs(startXY[0] - xy[0]);
  969. var h = Math.abs(startXY[1] - xy[1]);
  970. dragRegion.left = x;
  971. dragRegion.top = y;
  972. dragRegion.right = x+w;
  973. dragRegion.bottom = y+h;
  974. dragRegion.constrainTo(bodyRegion);
  975. proxy.setRegion(dragRegion);
  976. for(var i = 0, len = rs.length; i < len; i++){
  977. var r = rs[i], sel = dragRegion.intersect(r);
  978. if(sel && !r.selected){
  979. r.selected = true;
  980. view.select(i, true);
  981. }else if(!sel && r.selected){
  982. r.selected = false;
  983. view.deselect(i);
  984. }
  985. }
  986. }
  987. function onEnd(e){
  988. if (!Ext.isIE) {
  989. view.un('containerclick', cancelClick, view);
  990. }
  991. if(proxy){
  992. proxy.setDisplayed(false);
  993. }
  994. }
  995. function onRender(view){
  996. tracker = new Ext.dd.DragTracker({
  997. onBeforeStart: onBeforeStart,
  998. onStart: onStart,
  999. onDrag: onDrag,
  1000. onEnd: onEnd
  1001. });
  1002. tracker.initEl(view.el);
  1003. }
  1004. };Ext.ns('Ext.ux.form');
  1005. /**
  1006. * @class Ext.ux.form.FileUploadField
  1007. * @extends Ext.form.TextField
  1008. * Creates a file upload field.
  1009. * @xtype fileuploadfield
  1010. */
  1011. Ext.ux.form.FileUploadField = Ext.extend(Ext.form.TextField, {
  1012. /**
  1013. * @cfg {String} buttonText The button text to display on the upload button (defaults to
  1014. * 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
  1015. * value will be used instead if available.
  1016. */
  1017. buttonText: 'Browse...',
  1018. /**
  1019. * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
  1020. * text field (defaults to false). If true, all inherited TextField members will still be available.
  1021. */
  1022. buttonOnly: false,
  1023. /**
  1024. * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
  1025. * (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
  1026. */
  1027. buttonOffset: 3,
  1028. /**
  1029. * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
  1030. */
  1031. // private
  1032. readOnly: true,
  1033. /**
  1034. * @hide
  1035. * @method autoSize
  1036. */
  1037. autoSize: Ext.emptyFn,
  1038. // private
  1039. initComponent: function(){
  1040. Ext.ux.form.FileUploadField.superclass.initComponent.call(this);
  1041. this.addEvents(
  1042. /**
  1043. * @event fileselected
  1044. * Fires when the underlying file input field's value has changed from the user
  1045. * selecting a new file from the system file selection dialog.
  1046. * @param {Ext.ux.form.FileUploadField} this
  1047. * @param {String} value The file value returned by the underlying file input field
  1048. */
  1049. 'fileselected'
  1050. );
  1051. },
  1052. // private
  1053. onRender : function(ct, position){
  1054. Ext.ux.form.FileUploadField.superclass.onRender.call(this, ct, position);
  1055. this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
  1056. this.el.addClass('x-form-file-text');
  1057. this.el.dom.removeAttribute('name');
  1058. this.createFileInput();
  1059. var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
  1060. text: this.buttonText
  1061. });
  1062. this.button = new Ext.Button(Ext.apply(btnCfg, {
  1063. renderTo: this.wrap,
  1064. cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
  1065. }));
  1066. if(this.buttonOnly){
  1067. this.el.hide();
  1068. this.wrap.setWidth(this.button.getEl().getWidth());
  1069. }
  1070. this.bindListeners();
  1071. this.resizeEl = this.positionEl = this.wrap;
  1072. },
  1073. bindListeners: function(){
  1074. this.fileInput.on({
  1075. scope: this,
  1076. mouseenter: function() {
  1077. this.button.addClass(['x-btn-over','x-btn-focus'])
  1078. },
  1079. mouseleave: function(){
  1080. this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
  1081. },
  1082. mousedown: function(){
  1083. this.button.addClass('x-btn-click')
  1084. },
  1085. mouseup: function(){
  1086. this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
  1087. },
  1088. change: function(){
  1089. var v = this.fileInput.dom.value;
  1090. this.setValue(v);
  1091. this.fireEvent('fileselected', this, v);
  1092. }
  1093. });
  1094. },
  1095. createFileInput : function() {
  1096. this.fileInput = this.wrap.createChild({
  1097. id: this.getFileInputId(),
  1098. name: this.name||this.getId(),
  1099. cls: 'x-form-file',
  1100. tag: 'input',
  1101. type: 'file',
  1102. size: 1
  1103. });
  1104. },
  1105. reset : function(){
  1106. if (this.rendered) {
  1107. this.fileInput.remove();
  1108. this.createFileInput();
  1109. this.bindListeners();
  1110. }
  1111. Ext.ux.form.FileUploadField.superclass.reset.call(this);
  1112. },
  1113. // private
  1114. getFileInputId: function(){
  1115. return this.id + '-file';
  1116. },
  1117. // private
  1118. onResize : function(w, h){
  1119. Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);
  1120. this.wrap.setWidth(w);
  1121. if(!this.buttonOnly){
  1122. var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
  1123. this.el.setWidth(w);
  1124. }
  1125. },
  1126. // private
  1127. onDestroy: function(){
  1128. Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
  1129. Ext.destroy(this.fileInput, this.button, this.wrap);
  1130. },
  1131. onDisable: function(){
  1132. Ext.ux.form.FileUploadField.superclass.onDisable.call(this);
  1133. this.doDisable(true);
  1134. },
  1135. onEnable: function(){
  1136. Ext.ux.form.FileUploadField.superclass.onEnable.call(this);
  1137. this.doDisable(false);
  1138. },
  1139. // private
  1140. doDisable: function(disabled){
  1141. this.fileInput.dom.disabled = disabled;
  1142. this.button.setDisabled(disabled);
  1143. },
  1144. // private
  1145. preFocus : Ext.emptyFn,
  1146. // private
  1147. alignErrorIcon : function(){
  1148. this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
  1149. }
  1150. });
  1151. Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
  1152. // backwards compat
  1153. Ext.form.FileUploadField = Ext.ux.form.FileUploadField;
  1154. /**
  1155. * @class Ext.ux.GMapPanel
  1156. * @extends Ext.Panel
  1157. * @author Shea Frederick
  1158. */
  1159. Ext.ux.GMapPanel = Ext.extend(Ext.Panel, {
  1160. initComponent : function(){
  1161. var defConfig = {
  1162. plain: true,
  1163. zoomLevel: 3,
  1164. yaw: 180,
  1165. pitch: 0,
  1166. zoom: 0,
  1167. gmapType: 'map',
  1168. border: false
  1169. };
  1170. Ext.applyIf(this,defConfig);
  1171. Ext.ux.GMapPanel.superclass.initComponent.call(this);
  1172. },
  1173. afterRender : function(){
  1174. var wh = this.ownerCt.getSize();
  1175. Ext.applyIf(this, wh);
  1176. Ext.ux.GMapPanel.superclass.afterRender.call(this);
  1177. if (this.gmapType === 'map'){
  1178. this.gmap = new GMap2(this.body.dom);
  1179. }
  1180. if (this.gmapType === 'panorama'){
  1181. this.gmap = new GStreetviewPanorama(this.body.dom);
  1182. }
  1183. if (typeof this.addControl == 'object' && this.gmapType === 'map') {
  1184. this.gmap.addControl(this.addControl);
  1185. }
  1186. if (typeof this.setCenter === 'object') {
  1187. if (typeof this.setCenter.geoCodeAddr === 'string'){
  1188. this.geoCodeLookup(this.setCenter.geoCodeAddr);
  1189. }else{
  1190. if (this.gmapType === 'map'){
  1191. var point = new GLatLng(this.setCenter.lat,this.setCenter.lng);
  1192. this.gmap.setCenter(point, this.zoomLevel);
  1193. }
  1194. if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
  1195. this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear);
  1196. }
  1197. }
  1198. if (this.gmapType === 'panorama'){
  1199. this.gmap.setLocationAndPOV(new GLatLng(this.setCenter.lat,this.setCenter.lng), {yaw: this.yaw, pitch: this.pitch, zoom: this.zoom});
  1200. }
  1201. }
  1202. GEvent.bind(this.gmap, 'load', this, function(){
  1203. this.onMapReady();
  1204. });
  1205. },
  1206. onMapReady : function(){
  1207. this.addMarkers(this.markers);
  1208. this.addMapControls();
  1209. this.addOptions();
  1210. },
  1211. onResize : function(w, h){
  1212. if (typeof this.getMap() == 'object') {
  1213. this.gmap.checkResize();
  1214. }
  1215. Ext.ux.GMapPanel.superclass.onResize.call(this, w, h);
  1216. },
  1217. setSize : function(width, height, animate){
  1218. if (typeof this.getMap() == 'object') {
  1219. this.gmap.checkResize();
  1220. }
  1221. Ext.ux.GMapPanel.superclass.setSize.call(this, width, height, animate);
  1222. },
  1223. getMap : function(){
  1224. return this.gmap;
  1225. },
  1226. getCenter : function(){
  1227. return this.getMap().getCenter();
  1228. },
  1229. getCenterLatLng : function(){
  1230. var ll = this.getCenter();
  1231. return {lat: ll.lat(), lng: ll.lng()};
  1232. },
  1233. addMarkers : function(markers) {
  1234. if (Ext.isArray(markers)){
  1235. for (var i = 0; i < markers.length; i++) {
  1236. var mkr_point = new GLatLng(markers[i].lat,markers[i].lng);
  1237. this.addMarker(mkr_point,markers[i].marker,false,markers[i].setCenter, markers[i].listeners);
  1238. }
  1239. }
  1240. },
  1241. addMarker : function(point, marker, clear, center, listeners){
  1242. Ext.applyIf(marker,G_DEFAULT_ICON);
  1243. if (clear === true){
  1244. this.getMap().clearOverlays();
  1245. }
  1246. if (center === true) {
  1247. this.getMap().setCenter(point, this.zoomLevel);
  1248. }
  1249. var mark = new GMarker(point,marker);
  1250. if (typeof listeners === 'object'){
  1251. for (evt in listeners) {
  1252. GEvent.bind(mark, evt, this, listeners[evt]);
  1253. }
  1254. }
  1255. this.getMap().addOverlay(mark);
  1256. },
  1257. addMapControls : function(){
  1258. if (this.gmapType === 'map') {
  1259. if (Ext.isArray(this.mapControls)) {
  1260. for(i=0;i<this.mapControls.length;i++){
  1261. this.addMapControl(this.mapControls[i]);
  1262. }
  1263. }else if(typeof this.mapControls === 'string'){
  1264. this.addMapControl(this.mapControls);
  1265. }else if(typeof this.mapControls === 'object'){
  1266. this.getMap().addControl(this.mapControls);
  1267. }
  1268. }
  1269. },
  1270. addMapControl : function(mc){
  1271. var mcf = window[mc];
  1272. if (typeof mcf === 'function') {
  1273. this.getMap().addControl(new mcf());
  1274. }
  1275. },
  1276. addOptions : function(){
  1277. if (Ext.isArray(this.mapConfOpts)) {
  1278. var mc;
  1279. for(i=0;i<this.mapConfOpts.length;i++){
  1280. this.addOption(this.mapConfOpts[i]);
  1281. }
  1282. }else if(typeof this.mapConfOpts === 'string'){
  1283. this.addOption(this.mapConfOpts);
  1284. }
  1285. },
  1286. addOption : function(mc){
  1287. var mcf = this.getMap()[mc];
  1288. if (typeof mcf === 'function') {
  1289. this.getMap()[mc]();
  1290. }
  1291. },
  1292. geoCodeLookup : function(addr) {
  1293. this.geocoder = new GClientGeocoder();
  1294. this.geocoder.getLocations(addr, this.addAddressToMap.createDelegate(this));
  1295. },
  1296. addAddressToMap : function(response) {
  1297. if (!response || response.Status.code != 200) {
  1298. Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
  1299. }else{
  1300. place = response.Placemark[0];
  1301. addressinfo = place.AddressDetails;
  1302. accuracy = addressinfo.Accuracy;
  1303. if (accuracy === 0) {
  1304. Ext.MessageBox.alert('Unable to Locate Address', 'Unable to Locate the Address you provided');
  1305. }else{
  1306. if (accuracy < 7) {
  1307. Ext.MessageBox.alert('Address Accuracy', 'The address provided has a low accuracy.<br><br>Level '+accuracy+' Accuracy (8 = Exact Match, 1 = Vague Match)');
  1308. }else{
  1309. point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
  1310. if (typeof this.setCenter.marker === 'object' && typeof point === 'object'){
  1311. this.addMarker(point,this.setCenter.marker,this.setCenter.marker.clear,true, this.setCenter.listeners);
  1312. }
  1313. }
  1314. }
  1315. }
  1316. }
  1317. });
  1318. Ext.reg('gmappanel', Ext.ux.GMapPanel); Ext.namespace('Ext.ux.grid');
  1319. /**
  1320. * @class Ext.ux.grid.GridFilters
  1321. * @extends Ext.util.Observable
  1322. * <p>GridFilter is a plugin (<code>ptype='gridfilters'</code>) for grids that
  1323. * allow for a slightly more robust representation of filtering than what is
  1324. * provided by the default store.</p>
  1325. * <p>Filtering is adjusted by the user using the grid's column header menu
  1326. * (this menu can be disabled through configuration). Through this menu users
  1327. * can configure, enable, and disable filters for each column.</p>
  1328. * <p><b><u>Features:</u></b></p>
  1329. * <div class="mdetail-params"><ul>
  1330. * <li><b>Filtering implementations</b> :
  1331. * <div class="sub-desc">
  1332. * Default filtering for Strings, Numeric Ranges, Date Ranges, Lists (which can
  1333. * be backed by a Ext.data.Store), and Boolean. Additional custom filter types
  1334. * and menus are easily created by extending Ext.ux.grid.filter.Filter.
  1335. * </div></li>
  1336. * <li><b>Graphical indicators</b> :
  1337. * <div class="sub-desc">
  1338. * Columns that are filtered have {@link #filterCls a configurable css class}
  1339. * applied to the column headers.
  1340. * </div></li>
  1341. * <li><b>Paging</b> :
  1342. * <div class="sub-desc">
  1343. * If specified as a plugin to the grid's configured PagingToolbar, the current page
  1344. * will be reset to page 1 whenever you update the filters.
  1345. * </div></li>
  1346. * <li><b>Automatic Reconfiguration</b> :
  1347. * <div class="sub-desc">
  1348. * Filters automatically reconfigure when the grid 'reconfigure' event fires.
  1349. * </div></li>
  1350. * <li><b>Stateful</b> :
  1351. * Filter information will be persisted across page loads by specifying a
  1352. * <code>stateId</code> in the Grid configuration.
  1353. * <div class="sub-desc">
  1354. * The filter collection binds to the
  1355. * <code>{@link Ext.grid.GridPanel#beforestaterestore beforestaterestore}</code>
  1356. * and <code>{@link Ext.grid.GridPanel#beforestatesave beforestatesave}</code>
  1357. * events in order to be stateful.
  1358. * </div></li>
  1359. * <li><b>Grid Changes</b> :
  1360. * <div class="sub-desc"><ul>
  1361. * <li>A <code>filters</code> <i>property</i> is added to the grid pointing to
  1362. * this plugin.</li>
  1363. * <li>A <code>filterupdate</code> <i>event</i> is added to the grid and is
  1364. * fired upon onStateChange completion.</li>
  1365. * </ul></div></li>
  1366. * <li><b>Server side code examples</b> :
  1367. * <div class="sub-desc"><ul>
  1368. * <li><a href="http://www.vinylfox.com/extjs/grid-filter-php-backend-code.php">PHP</a> - (Thanks VinylFox)</li>
  1369. * <li><a href="http://extjs.com/forum/showthread.php?p=77326#post77326">Ruby on Rails</a> - (Thanks Zyclops)</li>
  1370. * <li><a href="http://extjs.com/forum/showthread.php?p=176596#post176596">Ruby on Rails</a> - (Thanks Rotomaul)</li>
  1371. * <li><a href="http://www.debatablybeta.com/posts/using-extjss-grid-filtering-with-django/">Python</a> - (Thanks Matt)</li>
  1372. * <li><a href="http://mcantrell.wordpress.com/2008/08/22/extjs-grids-and-grails/">Grails</a> - (Thanks Mike)</li>
  1373. * </ul></div></li>
  1374. * </ul></div>
  1375. * <p><b><u>Example usage:</u></b></p>
  1376. * <pre><code>
  1377. var store = new Ext.data.GroupingStore({
  1378. ...
  1379. });
  1380. var filters = new Ext.ux.grid.GridFilters({
  1381. autoReload: false, //don&#39;t reload automatically
  1382. local: true, //only filter locally
  1383. // filters may be configured through the plugin,
  1384. // or in the column definition within the column model configuration
  1385. filters: [{
  1386. type: 'numeric',
  1387. dataIndex: 'id'
  1388. }, {
  1389. type: 'string',
  1390. dataIndex: 'name'
  1391. }, {
  1392. type: 'numeric',
  1393. dataIndex: 'price'
  1394. }, {
  1395. type: 'date',
  1396. dataIndex: 'dateAdded'
  1397. }, {
  1398. type: 'list',
  1399. dataIndex: 'size',
  1400. options: ['extra small', 'small', 'medium', 'large', 'extra large'],
  1401. phpMode: true
  1402. }, {
  1403. type: 'boolean',
  1404. dataIndex: 'visible'
  1405. }]
  1406. });
  1407. var cm = new Ext.grid.ColumnModel([{
  1408. ...
  1409. }]);
  1410. var grid = new Ext.grid.GridPanel({
  1411. ds: store,
  1412. cm: cm,
  1413. view: new Ext.grid.GroupingView(),
  1414. plugins: [filters],
  1415. height: 400,
  1416. width: 700,
  1417. bbar: new Ext.PagingToolbar({
  1418. store: store,
  1419. pageSize: 15,
  1420. plugins: [filters] //reset page to page 1 if filters change
  1421. })
  1422. });
  1423. store.load({params: {start: 0, limit: 15}});
  1424. // a filters property is added to the grid
  1425. grid.filters
  1426. * </code></pre>
  1427. */
  1428. Ext.ux.grid.GridFilters = Ext.extend(Ext.util.Observable, {
  1429. /**
  1430. * @cfg {Boolean} autoReload
  1431. * Defaults to true, reloading the datasource when a filter change happens.
  1432. * Set this to false to prevent the datastore from being reloaded if there
  1433. * are changes to the filters. See <code>{@link updateBuffer}</code>.
  1434. */
  1435. autoReload : true,
  1436. /**
  1437. * @cfg {Boolean} encode
  1438. * Specify true for {@link #buildQuery} to use Ext.util.JSON.encode to
  1439. * encode the filter query parameter sent with a remote request.
  1440. * Defaults to false.
  1441. */
  1442. /**
  1443. * @cfg {Array} filters
  1444. * An Array of filters config objects. Refer to each filter type class for
  1445. * configuration details specific to each filter type. Filters for Strings,
  1446. * Numeric Ranges, Date Ranges, Lists, and Boolean are the standard filters
  1447. * available.
  1448. */
  1449. /**
  1450. * @cfg {String} filterCls
  1451. * The css class to be applied to column headers with active filters.
  1452. * Defaults to <tt>'ux-filterd-column'</tt>.
  1453. */
  1454. filterCls : 'ux-filtered-column',
  1455. /**
  1456. * @cfg {Boolean} local
  1457. * <tt>true</tt> to use Ext.data.Store filter functions (local filtering)
  1458. * instead of the default (<tt>false</tt>) server side filtering.
  1459. */
  1460. local : false,
  1461. /**
  1462. * @cfg {String} menuFilterText
  1463. * defaults to <tt>'Filters'</tt>.
  1464. */
  1465. menuFilterText : 'Filters',
  1466. /**
  1467. * @cfg {String} paramPrefix
  1468. * The url parameter prefix for the filters.
  1469. * Defaults to <tt>'filter'</tt>.
  1470. */
  1471. paramPrefix : 'filter',
  1472. /**
  1473. * @cfg {Boolean} showMenu
  1474. * Defaults to true, including a filter submenu in the default header menu.
  1475. */
  1476. showMenu : true,
  1477. /**
  1478. * @cfg {String} stateId
  1479. * Name of the value to be used to store state information.
  1480. */
  1481. stateId : undefined,
  1482. /**
  1483. * @cfg {Integer} updateBuffer
  1484. * Number of milliseconds to defer store updates since the last filter change.
  1485. */
  1486. updateBuffer : 500,
  1487. /** @private */
  1488. constructor : function (config) {
  1489. config = config || {};
  1490. this.deferredUpdate = new Ext.util.DelayedTask(this.reload, this);
  1491. this.filters = new Ext.util.MixedCollection();
  1492. this.filters.getKey = function (o) {
  1493. return o ? o.dataIndex : null;
  1494. };
  1495. this.addFilters(config.filters);
  1496. delete config.filters;
  1497. Ext.apply(this, config);
  1498. },
  1499. /** @private */
  1500. init : function (grid) {
  1501. if (grid instanceof Ext.grid.GridPanel) {
  1502. this.grid = grid;
  1503. this.bindStore(this.grid.getStore(), true);
  1504. // assumes no filters were passed in the constructor, so try and use ones from the colModel
  1505. if(this.filters.getCount() == 0){
  1506. this.addFilters(this.grid.getColumnModel());
  1507. }
  1508. this.grid.filters = this;
  1509. this.grid.addEvents({'filterupdate': true});
  1510. grid.on({
  1511. scope: this,
  1512. beforestaterestore: this.applyState,
  1513. beforestatesave: this.saveState,
  1514. beforedestroy: this.destroy,
  1515. reconfigure: this.onReconfigure
  1516. });
  1517. if (grid.rendered){
  1518. this.onRender();
  1519. } else {
  1520. grid.on({
  1521. scope: this,
  1522. single: true,
  1523. render: this.onRender
  1524. });
  1525. }
  1526. } else if (grid instanceof Ext.PagingToolbar) {
  1527. this.toolbar = grid;
  1528. }
  1529. },
  1530. /**
  1531. * @private
  1532. * Handler for the grid's beforestaterestore event (fires before the state of the
  1533. * grid is restored).
  1534. * @param {Object} grid The grid object
  1535. * @param {Object} state The hash of state values returned from the StateProvider.
  1536. */
  1537. applyState : function (grid, state) {
  1538. var key, filter;
  1539. this.applyingState = true;
  1540. this.clearFilters();
  1541. if (state.filters) {
  1542. for (key in state.filters) {
  1543. filter = this.filters.get(key);
  1544. if (filter) {
  1545. filter.setValue(state.filters[key]);
  1546. filter.setActive(true);
  1547. }
  1548. }
  1549. }
  1550. this.deferredUpdate.cancel();
  1551. if (this.local) {
  1552. this.reload();
  1553. }
  1554. delete this.applyingState;
  1555. delete state.filters;
  1556. },
  1557. /**
  1558. * Saves the state of all active filters
  1559. * @param {Object} grid
  1560. * @param {Object} state
  1561. * @return {Boolean}
  1562. */
  1563. saveState : function (grid, state) {
  1564. var filters = {};
  1565. this.filters.each(function (filter) {
  1566. if (filter.active) {
  1567. filters[filter.dataIndex] = filter.getValue();
  1568. }
  1569. });
  1570. return (state.filters = filters);
  1571. },
  1572. /**
  1573. * @private
  1574. * Handler called when the grid is rendered
  1575. */
  1576. onRender : function () {
  1577. this.grid.getView().on('refresh', this.onRefresh, this);
  1578. this.createMenu();
  1579. },
  1580. /**
  1581. * @private
  1582. * Handler called by the grid 'beforedestroy' event
  1583. */
  1584. destroy : function () {
  1585. this.removeAll();
  1586. this.purgeListeners();
  1587. if(this.filterMenu){
  1588. Ext.menu.MenuMgr.unregister(this.filterMenu);
  1589. this.filterMenu.destroy();
  1590. this.filterMenu = this.menu.menu = null;
  1591. }
  1592. },
  1593. /**
  1594. * Remove all filters, permanently destroying them.
  1595. */
  1596. removeAll : function () {
  1597. if(this.filters){
  1598. Ext.destroy.apply(Ext, this.filters.items);
  1599. // remove all items from the collection
  1600. this.filters.clear();
  1601. }
  1602. },
  1603. /**
  1604. * Changes the data store bound to this view and refreshes it.
  1605. * @param {Store} store The store to bind to this view
  1606. */
  1607. bindStore : function(store, initial){
  1608. if(!initial && this.store){
  1609. if (this.local) {
  1610. store.un('load', this.onLoad, this);
  1611. } else {
  1612. store.un('beforeload', this.onBeforeLoad, this);
  1613. }
  1614. }
  1615. if(store){
  1616. if (this.local) {
  1617. store.on('load', this.onLoad, this);
  1618. } else {
  1619. store.on('beforeload', this.onBeforeLoad, this);
  1620. }
  1621. }
  1622. this.store = store;
  1623. },
  1624. /**
  1625. * @private
  1626. * Handler called when the grid reconfigure event fires
  1627. */
  1628. onReconfigure : function () {
  1629. this.bindStore(this.grid.getStore());
  1630. this.store.clearFilter();
  1631. this.removeAll();
  1632. this.addFilters(this.grid.getColumnModel());
  1633. this.updateColumnHeadings();
  1634. },
  1635. createMenu : function () {
  1636. var view = this.grid.getView(),
  1637. hmenu = view.hmenu;
  1638. if (this.showMenu && hmenu) {
  1639. this.sep = hmenu.addSeparator();
  1640. this.filterMenu = new Ext.menu.Menu({
  1641. id: this.grid.id + '-filters-menu'
  1642. });
  1643. this.menu = hmenu.add({
  1644. checked: false,
  1645. itemId: 'filters',
  1646. text: this.menuFilterText,
  1647. menu: this.filterMenu
  1648. });
  1649. this.menu.on({
  1650. scope: this,
  1651. checkchange: this.onCheckChange,
  1652. beforecheckchange: this.onBeforeCheck
  1653. });
  1654. hmenu.on('beforeshow', this.onMenu, this);
  1655. }
  1656. this.updateColumnHeadings();
  1657. },
  1658. /**
  1659. * @private
  1660. * Get the filter menu from the filters MixedCollection based on the clicked header
  1661. */
  1662. getMenuFilter : function () {
  1663. var view = this.grid.getView();
  1664. if (!view || view.hdCtxIndex === undefined) {
  1665. return null;
  1666. }
  1667. return this.filters.get(
  1668. view.cm.config[view.hdCtxIndex].dataIndex
  1669. );
  1670. },
  1671. /**
  1672. * @private
  1673. * Handler called by the grid's hmenu beforeshow event
  1674. */
  1675. onMenu : function (filterMenu) {
  1676. var filter = this.getMenuFilter();
  1677. if (filter) {
  1678. /*
  1679. TODO: lazy rendering
  1680. if (!filter.menu) {
  1681. filter.menu = filter.createMenu();
  1682. }
  1683. */
  1684. this.menu.menu = filter.menu;
  1685. this.menu.setChecked(filter.active, false);
  1686. // disable the menu if filter.disabled explicitly set to true
  1687. this.menu.setDisabled(filter.disabled === true);
  1688. }
  1689. this.menu.setVisible(filter !== undefined);
  1690. this.sep.setVisible(filter !== undefined);
  1691. },
  1692. /** @private */
  1693. onCheckChange : function (item, value) {
  1694. this.getMenuFilter().setActive(value);
  1695. },
  1696. /** @private */
  1697. onBeforeCheck : function (check, value) {
  1698. return !value || this.getMenuFilter().isActivatable();
  1699. },
  1700. /**
  1701. * @private
  1702. * Handler for all events on filters.
  1703. * @param {String} event Event name
  1704. * @param {Object} filter Standard signature of the event before the event is fired
  1705. */
  1706. onStateChange : function (event, filter) {
  1707. if (event === 'serialize') {
  1708. return;
  1709. }
  1710. if (filter == this.getMenuFilter()) {
  1711. this.menu.setChecked(filter.active, false);
  1712. }
  1713. if ((this.autoReload || this.local) && !this.applyingState) {
  1714. this.deferredUpdate.delay(this.updateBuffer);
  1715. }
  1716. this.updateColumnHeadings();
  1717. if (!this.applyingState) {
  1718. this.grid.saveState();
  1719. }
  1720. this.grid.fireEvent('filterupdate', this, filter);
  1721. },
  1722. /**
  1723. * @private
  1724. * Handler for store's beforeload event when configured for remote filtering
  1725. * @param {Object} store
  1726. * @param {Object} options
  1727. */
  1728. onBeforeLoad : function (store, options) {
  1729. options.params = options.params || {};
  1730. this.cleanParams(options.params);
  1731. var params = this.buildQuery(this.getFilterData());
  1732. Ext.apply(options.params, params);
  1733. },
  1734. /**
  1735. * @private
  1736. * Handler for store's load event when configured for local filtering
  1737. * @param {Object} store
  1738. * @param {Object} options
  1739. */
  1740. onLoad : function (store, options) {
  1741. store.filterBy(this.getRecordFilter());
  1742. },
  1743. /**
  1744. * @private
  1745. * Handler called when the grid's view is refreshed
  1746. */
  1747. onRefresh : function () {
  1748. this.updateColumnHeadings();
  1749. },
  1750. /**
  1751. * Update the styles for the header row based on the active filters
  1752. */
  1753. updateColumnHeadings : function () {
  1754. var view = this.grid.getView(),
  1755. i, len, filter;
  1756. if (view.mainHd) {
  1757. for (i = 0, len = view.cm.config.length; i < len; i++) {
  1758. filter = this.getFilter(view.cm.config[i].dataIndex);
  1759. Ext.fly(view.getHeaderCell(i))[filter && filter.active ? 'addClass' : 'removeClass'](this.filterCls);
  1760. }
  1761. }
  1762. },
  1763. /** @private */
  1764. reload : function () {
  1765. if (this.local) {
  1766. this.grid.store.clearFilter(true);
  1767. this.grid.store.filterBy(this.getRecordFilter());
  1768. } else {
  1769. var start,
  1770. store = this.grid.store;
  1771. this.deferredUpdate.cancel();
  1772. if (this.toolbar) {
  1773. start = store.paramNames.start;
  1774. if (store.lastOptions && store.lastOptions.params && store.lastOptions.params[start]) {
  1775. store.lastOptions.params[start] = 0;
  1776. }
  1777. }
  1778. store.reload();
  1779. }
  1780. },
  1781. /**
  1782. * Method factory that generates a record validator for the filters active at the time
  1783. * of invokation.
  1784. * @private
  1785. */
  1786. getRecordFilter : function () {
  1787. var f = [], len, i;
  1788. this.filters.each(function (filter) {
  1789. if (filter.active) {
  1790. f.push(filter);
  1791. }
  1792. });
  1793. len = f.length;
  1794. return function (record) {
  1795. for (i = 0; i < len; i++) {
  1796. if (!f[i].validateRecord(record)) {
  1797. return false;
  1798. }
  1799. }
  1800. return true;
  1801. };
  1802. },
  1803. /**
  1804. * Adds a filter to the collection and observes it for state change.
  1805. * @param {Object/Ext.ux.grid.filter.Filter} config A filter configuration or a filter object.
  1806. * @return {Ext.ux.grid.filter.Filter} The existing or newly created filter object.
  1807. */
  1808. addFilter : function (config) {
  1809. var Cls = this.getFilterClass(config.type),
  1810. filter = config.menu ? config : (new Cls(config));
  1811. this.filters.add(filter);
  1812. Ext.util.Observable.capture(filter, this.onStateChange, this);
  1813. return filter;
  1814. },
  1815. /**
  1816. * Adds filters to the collection.
  1817. * @param {Array/Ext.grid.ColumnModel} filters Either an Array of
  1818. * filter configuration objects or an Ext.grid.ColumnModel. The columns
  1819. * of a passed Ext.grid.ColumnModel will be examined for a <code>filter</code>
  1820. * property and, if present, will be used as the filter configuration object.
  1821. */
  1822. addFilters : function (filters) {
  1823. if (filters) {
  1824. var i, len, filter, cm = false, dI;
  1825. if (filters instanceof Ext.grid.ColumnModel) {
  1826. filters = filters.config;
  1827. cm = true;
  1828. }
  1829. for (i = 0, len = filters.length; i < len; i++) {
  1830. filter = false;
  1831. if (cm) {
  1832. dI = filters[i].dataIndex;
  1833. filter = filters[i].filter || filters[i].filterable;
  1834. if (filter){
  1835. filter = (filter === true) ? {} : filter;
  1836. Ext.apply(filter, {dataIndex:dI});
  1837. // filter type is specified in order of preference:
  1838. // filter type specified in config
  1839. // type specified in store's field's type config
  1840. filter.type = filter.type || this.store.fields.get(dI).type.type;
  1841. }
  1842. } else {
  1843. filter = filters[i];
  1844. }
  1845. // if filter config found add filter for the column
  1846. if (filter) {
  1847. this.addFilter(filter);
  1848. }
  1849. }
  1850. }
  1851. },
  1852. /**
  1853. * Returns a filter for the given dataIndex, if one exists.
  1854. * @param {String} dataIndex The dataIndex of the desired filter object.
  1855. * @return {Ext.ux.grid.filter.Filter}
  1856. */
  1857. getFilter : function (dataIndex) {
  1858. return this.filters.get(dataIndex);
  1859. },
  1860. /**
  1861. * Turns all filters off. This does not clear the configuration information
  1862. * (see {@link #removeAll}).
  1863. */
  1864. clearFilters : function () {
  1865. this.filters.each(function (filter) {
  1866. filter.setActive(false);
  1867. });
  1868. },
  1869. /**
  1870. * Returns an Array of the currently active filters.
  1871. * @return {Array} filters Array of the currently active filters.
  1872. */
  1873. getFilterData : function () {
  1874. var filters = [], i, len;
  1875. this.filters.each(function (f) {
  1876. if (f.active) {
  1877. var d = [].concat(f.serialize());
  1878. for (i = 0, len = d.length; i < len; i++) {
  1879. filters.push({
  1880. field: f.dataIndex,
  1881. data: d[i]
  1882. });
  1883. }
  1884. }
  1885. });
  1886. return filters;
  1887. },
  1888. /**
  1889. * Function to take the active filters data and build it into a query.
  1890. * The format of the query depends on the <code>{@link #encode}</code>
  1891. * configuration:
  1892. * <div class="mdetail-params"><ul>
  1893. *
  1894. * <li><b><tt>false</tt></b> : <i>Default</i>
  1895. * <div class="sub-desc">
  1896. * Flatten into query string of the form (assuming <code>{@link #paramPrefix}='filters'</code>:
  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. * <li><b><tt>true</tt></b> :
  1905. * <div class="sub-desc">
  1906. * JSON encode the filter data
  1907. * <pre><code>
  1908. filters[0][field]="someDataIndex"&
  1909. filters[0][data][comparison]="someValue1"&
  1910. filters[0][data][type]="someValue2"&
  1911. filters[0][data][value]="someValue3"&
  1912. * </code></pre>
  1913. * </div></li>
  1914. * </ul></div>
  1915. * Override this method to customize the format of the filter query for remote requests.
  1916. * @param {Array} filters A collection of objects representing active filters and their configuration.
  1917. * Each element will take the form of {field: dataIndex, data: filterConf}. dataIndex is not assured
  1918. * to be unique as any one filter may be a composite of more basic filters for the same dataIndex.
  1919. * @return {Object} Query keys and values
  1920. */
  1921. buildQuery : function (filters) {
  1922. var p = {}, i, f, root, dataPrefix, key, tmp,
  1923. len = filters.length;
  1924. if (!this.encode){
  1925. for (i = 0; i < len; i++) {
  1926. f = filters[i];
  1927. root = [this.paramPrefix, '[', i, ']'].join('');
  1928. p[root + '[field]'] = f.field;
  1929. dataPrefix = root + '[data]';
  1930. for (key in f.data) {
  1931. p[[dataPrefix, '[', key, ']'].join('')] = f.data[key];
  1932. }
  1933. }
  1934. } else {
  1935. tmp = [];
  1936. for (i = 0; i < len; i++) {
  1937. f = filters[i];
  1938. tmp.push(Ext.apply(
  1939. {},
  1940. {field: f.field},
  1941. f.data
  1942. ));
  1943. }
  1944. // only build if there is active filter
  1945. if (tmp.length > 0){
  1946. p[this.paramPrefix] = Ext.util.JSON.encode(tmp);
  1947. }
  1948. }
  1949. return p;
  1950. },
  1951. /**
  1952. * Removes filter related query parameters from the provided object.
  1953. * @param {Object} p Query parameters that may contain filter related fields.
  1954. */
  1955. cleanParams : function (p) {
  1956. // if encoding just delete the property
  1957. if (this.encode) {
  1958. delete p[this.paramPrefix];
  1959. // otherwise scrub the object of filter data
  1960. } else {
  1961. var regex, key;
  1962. regex = new RegExp('^' + this.paramPrefix + '\[[0-9]+\]');
  1963. for (key in p) {
  1964. if (regex.test(key)) {
  1965. delete p[key];
  1966. }
  1967. }
  1968. }
  1969. },
  1970. /**
  1971. * Function for locating filter classes, overwrite this with your favorite
  1972. * loader to provide dynamic filter loading.
  1973. * @param {String} type The type of filter to load ('Filter' is automatically
  1974. * appended to the passed type; eg, 'string' becomes 'StringFilter').
  1975. * @return {Class} The Ext.ux.grid.filter.Class
  1976. */
  1977. getFilterClass : function (type) {
  1978. // map the supported Ext.data.Field type values into a supported filter
  1979. switch(type) {
  1980. case 'auto':
  1981. type = 'string';
  1982. break;
  1983. case 'int':
  1984. case 'float':
  1985. type = 'numeric';
  1986. break;
  1987. case 'bool':
  1988. type = 'boolean';
  1989. break;
  1990. }
  1991. return Ext.ux.grid.filter[type.substr(0, 1).toUpperCase() + type.substr(1) + 'Filter'];
  1992. }
  1993. });
  1994. // register ptype
  1995. Ext.preg('gridfilters', Ext.ux.grid.GridFilters);
  1996. Ext.namespace('Ext.ux.grid.filter');
  1997. /**
  1998. * @class Ext.ux.grid.filter.Filter
  1999. * @extends Ext.util.Observable
  2000. * Abstract base class for filter implementations.
  2001. */
  2002. Ext.ux.grid.filter.Filter = Ext.extend(Ext.util.Observable, {
  2003. /**
  2004. * @cfg {Boolean} active
  2005. * Indicates the initial status of the filter (defaults to false).
  2006. */
  2007. active : false,
  2008. /**
  2009. * True if this filter is active. Use setActive() to alter after configuration.
  2010. * @type Boolean
  2011. * @property active
  2012. */
  2013. /**
  2014. * @cfg {String} dataIndex
  2015. * The {@link Ext.data.Store} dataIndex of the field this filter represents.
  2016. * The dataIndex does not actually have to exist in the store.
  2017. */
  2018. dataIndex : null,
  2019. /**
  2020. * The filter configuration menu that will be installed into the filter submenu of a column menu.
  2021. * @type Ext.menu.Menu
  2022. * @property
  2023. */
  2024. menu : null,
  2025. /**
  2026. * @cfg {Number} updateBuffer
  2027. * Number of milliseconds to wait after user interaction to fire an update. Only supported
  2028. * by filters: 'list', 'numeric', and 'string'. Defaults to 500.
  2029. */
  2030. updateBuffer : 500,
  2031. constructor : function (config) {
  2032. Ext.apply(this, config);
  2033. this.addEvents(
  2034. /**
  2035. * @event activate
  2036. * Fires when an inactive filter becomes active
  2037. * @param {Ext.ux.grid.filter.Filter} this
  2038. */
  2039. 'activate',
  2040. /**
  2041. * @event deactivate
  2042. * Fires when an active filter becomes inactive
  2043. * @param {Ext.ux.grid.filter.Filter} this
  2044. */
  2045. 'deactivate',
  2046. /**
  2047. * @event serialize
  2048. * Fires after the serialization process. Use this to attach additional parameters to serialization
  2049. * data before it is encoded and sent to the server.
  2050. * @param {Array/Object} data A map or collection of maps representing the current filter configuration.
  2051. * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.
  2052. */
  2053. 'serialize',
  2054. /**
  2055. * @event update
  2056. * Fires when a filter configuration has changed
  2057. * @param {Ext.ux.grid.filter.Filter} this The filter object.
  2058. */
  2059. 'update'
  2060. );
  2061. Ext.ux.grid.filter.Filter.superclass.constructor.call(this);
  2062. this.menu = new Ext.menu.Menu();
  2063. this.init(config);
  2064. if(config && config.value){
  2065. this.setValue(config.value);
  2066. this.setActive(config.active !== false, true);
  2067. delete config.value;
  2068. }
  2069. },
  2070. /**
  2071. * Destroys this filter by purging any event listeners, and removing any menus.
  2072. */
  2073. destroy : function(){
  2074. if (this.menu){
  2075. this.menu.destroy();
  2076. }
  2077. this.purgeListeners();
  2078. },
  2079. /**
  2080. * Template method to be implemented by all subclasses that is to
  2081. * initialize the filter and install required menu items.
  2082. * Defaults to Ext.emptyFn.
  2083. */
  2084. init : Ext.emptyFn,
  2085. /**
  2086. * Template method to be implemented by all subclasses that is to
  2087. * get and return the value of the filter.
  2088. * Defaults to Ext.emptyFn.
  2089. * @return {Object} The 'serialized' form of this filter
  2090. * @methodOf Ext.ux.grid.filter.Filter
  2091. */
  2092. getValue : Ext.emptyFn,
  2093. /**
  2094. * Template method to be implemented by all subclasses that is to
  2095. * set the value of the filter and fire the 'update' event.
  2096. * Defaults to Ext.emptyFn.
  2097. * @param {Object} data The value to set the filter
  2098. * @methodOf Ext.ux.grid.filter.Filter
  2099. */
  2100. setValue : Ext.emptyFn,
  2101. /**
  2102. * Template method to be implemented by all subclasses that is to
  2103. * return <tt>true</tt> if the filter has enough configuration information to be activated.
  2104. * Defaults to <tt>return true</tt>.
  2105. * @return {Boolean}
  2106. */
  2107. isActivatable : function(){
  2108. return true;
  2109. },
  2110. /**
  2111. * Template method to be implemented by all subclasses that is to
  2112. * get and return serialized filter data for transmission to the server.
  2113. * Defaults to Ext.emptyFn.
  2114. */
  2115. getSerialArgs : Ext.emptyFn,
  2116. /**
  2117. * Template method to be implemented by all subclasses that is to
  2118. * validates the provided Ext.data.Record against the filters configuration.
  2119. * Defaults to <tt>return true</tt>.
  2120. * @param {Ext.data.Record} record The record to validate
  2121. * @return {Boolean} true if the record is valid within the bounds
  2122. * of the filter, false otherwise.
  2123. */
  2124. validateRecord : function(){
  2125. return true;
  2126. },
  2127. /**
  2128. * Returns the serialized filter data for transmission to the server
  2129. * and fires the 'serialize' event.
  2130. * @return {Object/Array} An object or collection of objects containing
  2131. * key value pairs representing the current configuration of the filter.
  2132. * @methodOf Ext.ux.grid.filter.Filter
  2133. */
  2134. serialize : function(){
  2135. var args = this.getSerialArgs();
  2136. this.fireEvent('serialize', args, this);
  2137. return args;
  2138. },
  2139. /** @private */
  2140. fireUpdate : function(){
  2141. if (this.active) {
  2142. this.fireEvent('update', this);
  2143. }
  2144. this.setActive(this.isActivatable());
  2145. },
  2146. /**
  2147. * Sets the status of the filter and fires the appropriate events.
  2148. * @param {Boolean} active The new filter state.
  2149. * @param {Boolean} suppressEvent True to prevent events from being fired.
  2150. * @methodOf Ext.ux.grid.filter.Filter
  2151. */
  2152. setActive : function(active, suppressEvent){
  2153. if(this.active != active){
  2154. this.active = active;
  2155. if (suppressEvent !== true) {
  2156. this.fireEvent(active ? 'activate' : 'deactivate', this);
  2157. }
  2158. }
  2159. }
  2160. });/**
  2161. * @class Ext.ux.grid.filter.BooleanFilter
  2162. * @extends Ext.ux.grid.filter.Filter
  2163. * Boolean filters use unique radio group IDs (so you can have more than one!)
  2164. * <p><b><u>Example Usage:</u></b></p>
  2165. * <pre><code>
  2166. var filters = new Ext.ux.grid.GridFilters({
  2167. ...
  2168. filters: [{
  2169. // required configs
  2170. type: 'boolean',
  2171. dataIndex: 'visible'
  2172. // optional configs
  2173. defaultValue: null, // leave unselected (false selected by default)
  2174. yesText: 'Yes', // default
  2175. noText: 'No' // default
  2176. }]
  2177. });
  2178. * </code></pre>
  2179. */
  2180. Ext.ux.grid.filter.BooleanFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
  2181. /**
  2182. * @cfg {Boolean} defaultValue
  2183. * Set this to null if you do not want either option to be checked by default. Defaults to false.
  2184. */
  2185. defaultValue : false,
  2186. /**
  2187. * @cfg {String} yesText
  2188. * Defaults to 'Yes'.
  2189. */
  2190. yesText : 'Yes',
  2191. /**
  2192. * @cfg {String} noText
  2193. * Defaults to 'No'.
  2194. */
  2195. noText : 'No',
  2196. /**
  2197. * @private
  2198. * Template method that is to initialize the filter and install required menu items.
  2199. */
  2200. init : function (config) {
  2201. var gId = Ext.id();
  2202. this.options = [
  2203. new Ext.menu.CheckItem({text: this.yesText, group: gId, checked: this.defaultValue === true}),
  2204. new Ext.menu.CheckItem({text: this.noText, group: gId, checked: this.defaultValue === false})];
  2205. this.menu.add(this.options[0], this.options[1]);
  2206. for(var i=0; i<this.options.length; i++){
  2207. this.options[i].on('click', this.fireUpdate, this);
  2208. this.options[i].on('checkchange', this.fireUpdate, this);
  2209. }
  2210. },
  2211. /**
  2212. * @private
  2213. * Template method that is to get and return the value of the filter.
  2214. * @return {String} The value of this filter
  2215. */
  2216. getValue : function () {
  2217. return this.options[0].checked;
  2218. },
  2219. /**
  2220. * @private
  2221. * Template method that is to set the value of the filter.
  2222. * @param {Object} value The value to set the filter
  2223. */
  2224. setValue : function (value) {
  2225. this.options[value ? 0 : 1].setChecked(true);
  2226. },
  2227. /**
  2228. * @private
  2229. * Template method that is to get and return serialized filter data for
  2230. * transmission to the server.
  2231. * @return {Object/Array} An object or collection of objects containing
  2232. * key value pairs representing the current configuration of the filter.
  2233. */
  2234. getSerialArgs : function () {
  2235. var args = {type: 'boolean', value: this.getValue()};
  2236. return args;
  2237. },
  2238. /**
  2239. * Template method that is to validate the provided Ext.data.Record
  2240. * against the filters configuration.
  2241. * @param {Ext.data.Record} record The record to validate
  2242. * @return {Boolean} true if the record is valid within the bounds
  2243. * of the filter, false otherwise.
  2244. */
  2245. validateRecord : function (record) {
  2246. return record.get(this.dataIndex) == this.getValue();
  2247. }
  2248. });/**
  2249. * @class Ext.ux.grid.filter.DateFilter
  2250. * @extends Ext.ux.grid.filter.Filter
  2251. * Filter by a configurable Ext.menu.DateMenu
  2252. * <p><b><u>Example Usage:</u></b></p>
  2253. * <pre><code>
  2254. var filters = new Ext.ux.grid.GridFilters({
  2255. ...
  2256. filters: [{
  2257. // required configs
  2258. type: 'date',
  2259. dataIndex: 'dateAdded',
  2260. // optional configs
  2261. dateFormat: 'm/d/Y', // default
  2262. beforeText: 'Before', // default
  2263. afterText: 'After', // default
  2264. onText: 'On', // default
  2265. pickerOpts: {
  2266. // any DateMenu configs
  2267. },
  2268. active: true // default is false
  2269. }]
  2270. });
  2271. * </code></pre>
  2272. */
  2273. Ext.ux.grid.filter.DateFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
  2274. /**
  2275. * @cfg {String} afterText
  2276. * Defaults to 'After'.
  2277. */
  2278. afterText : 'After',
  2279. /**
  2280. * @cfg {String} beforeText
  2281. * Defaults to 'Before'.
  2282. */
  2283. beforeText : 'Before',
  2284. /**
  2285. * @cfg {Object} compareMap
  2286. * Map for assigning the comparison values used in serialization.
  2287. */
  2288. compareMap : {
  2289. before: 'lt',
  2290. after: 'gt',
  2291. on: 'eq'
  2292. },
  2293. /**
  2294. * @cfg {String} dateFormat
  2295. * The date format to return when using getValue.
  2296. * Defaults to 'm/d/Y'.
  2297. */
  2298. dateFormat : 'm/d/Y',
  2299. /**
  2300. * @cfg {Date} maxDate
  2301. * Allowable date as passed to the Ext.DatePicker
  2302. * Defaults to undefined.
  2303. */
  2304. /**
  2305. * @cfg {Date} minDate
  2306. * Allowable date as passed to the Ext.DatePicker
  2307. * Defaults to undefined.
  2308. */
  2309. /**
  2310. * @cfg {Array} menuItems
  2311. * The items to be shown in this menu
  2312. * Defaults to:<pre>
  2313. * menuItems : ['before', 'after', '-', 'on'],
  2314. * </pre>
  2315. */
  2316. menuItems : ['before', 'after', '-', 'on'],
  2317. /**
  2318. * @cfg {Object} menuItemCfgs
  2319. * Default configuration options for each menu item
  2320. */
  2321. menuItemCfgs : {
  2322. selectOnFocus: true,
  2323. width: 125
  2324. },
  2325. /**
  2326. * @cfg {String} onText
  2327. * Defaults to 'On'.
  2328. */
  2329. onText : 'On',
  2330. /**
  2331. * @cfg {Object} pickerOpts
  2332. * Configuration options for the date picker associated with each field.
  2333. */
  2334. pickerOpts : {},
  2335. /**
  2336. * @private
  2337. * Template method that is to initialize the filter and install required menu items.
  2338. */
  2339. init : function (config) {
  2340. var menuCfg, i, len, item, cfg, Cls;
  2341. menuCfg = Ext.apply(this.pickerOpts, {
  2342. minDate: this.minDate,
  2343. maxDate: this.maxDate,
  2344. format: this.dateFormat,
  2345. listeners: {
  2346. scope: this,
  2347. select: this.onMenuSelect
  2348. }
  2349. });
  2350. this.fields = {};
  2351. for (i = 0, len = this.menuItems.length; i < len; i++) {
  2352. item = this.menuItems[i];
  2353. if (item !== '-') {
  2354. cfg = {
  2355. itemId: 'range-' + item,
  2356. text: this[item + 'Text'],
  2357. menu: new Ext.menu.DateMenu(
  2358. Ext.apply(menuCfg, {
  2359. itemId: item
  2360. })
  2361. ),
  2362. listeners: {
  2363. scope: this,
  2364. checkchange: this.onCheckChange
  2365. }
  2366. };
  2367. Cls = Ext.menu.CheckItem;
  2368. item = this.fields[item] = new Cls(cfg);
  2369. }
  2370. //this.add(item);
  2371. this.menu.add(item);
  2372. }
  2373. },
  2374. onCheckChange : function () {
  2375. this.setActive(this.isActivatable());
  2376. this.fireEvent('update', this);
  2377. },
  2378. /**
  2379. * @private
  2380. * Handler method called when there is a keyup event on an input
  2381. * item of this menu.
  2382. */
  2383. onInputKeyUp : function (field, e) {
  2384. var k = e.getKey();
  2385. if (k == e.RETURN && field.isValid()) {
  2386. e.stopEvent();
  2387. this.menu.hide(true);
  2388. return;
  2389. }
  2390. },
  2391. /**
  2392. * Handler for when the menu for a field fires the 'select' event
  2393. * @param {Object} date
  2394. * @param {Object} menuItem
  2395. * @param {Object} value
  2396. * @param {Object} picker
  2397. */
  2398. onMenuSelect : function (menuItem, value, picker) {
  2399. var fields = this.fields,
  2400. field = this.fields[menuItem.itemId];
  2401. field.setChecked(true);
  2402. if (field == fields.on) {
  2403. fields.before.setChecked(false, true);
  2404. fields.after.setChecked(false, true);
  2405. } else {
  2406. fields.on.setChecked(false, true);
  2407. if (field == fields.after && fields.before.menu.picker.value < value) {
  2408. fields.before.setChecked(false, true);
  2409. } else if (field == fields.before && fields.after.menu.picker.value > value) {
  2410. fields.after.setChecked(false, true);
  2411. }
  2412. }
  2413. this.fireEvent('update', this);
  2414. },
  2415. /**
  2416. * @private
  2417. * Template method that is to get and return the value of the filter.
  2418. * @return {String} The value of this filter
  2419. */
  2420. getValue : function () {
  2421. var key, result = {};
  2422. for (key in this.fields) {
  2423. if (this.fields[key].checked) {
  2424. result[key] = this.fields[key].menu.picker.getValue();
  2425. }
  2426. }
  2427. return result;
  2428. },
  2429. /**
  2430. * @private
  2431. * Template method that is to set the value of the filter.
  2432. * @param {Object} value The value to set the filter
  2433. * @param {Boolean} preserve true to preserve the checked status
  2434. * of the other fields. Defaults to false, unchecking the
  2435. * other fields
  2436. */
  2437. setValue : function (value, preserve) {
  2438. var key;
  2439. for (key in this.fields) {
  2440. if(value[key]){
  2441. this.fields[key].menu.picker.setValue(value[key]);
  2442. this.fields[key].setChecked(true);
  2443. } else if (!preserve) {
  2444. this.fields[key].setChecked(false);
  2445. }
  2446. }
  2447. this.fireEvent('update', this);
  2448. },
  2449. /**
  2450. * @private
  2451. * Template method that is to return <tt>true</tt> if the filter
  2452. * has enough configuration information to be activated.
  2453. * @return {Boolean}
  2454. */
  2455. isActivatable : function () {
  2456. var key;
  2457. for (key in this.fields) {
  2458. if (this.fields[key].checked) {
  2459. return true;
  2460. }
  2461. }
  2462. return false;
  2463. },
  2464. /**
  2465. * @private
  2466. * Template method that is to get and return serialized filter data for
  2467. * transmission to the server.
  2468. * @return {Object/Array} An object or collection of objects containing
  2469. * key value pairs representing the current configuration of the filter.
  2470. */
  2471. getSerialArgs : function () {
  2472. var args = [];
  2473. for (var key in this.fields) {
  2474. if(this.fields[key].checked){
  2475. args.push({
  2476. type: 'date',
  2477. comparison: this.compareMap[key],
  2478. value: this.getFieldValue(key).format(this.dateFormat)
  2479. });
  2480. }
  2481. }
  2482. return args;
  2483. },
  2484. /**
  2485. * Get and return the date menu picker value
  2486. * @param {String} item The field identifier ('before', 'after', 'on')
  2487. * @return {Date} Gets the current selected value of the date field
  2488. */
  2489. getFieldValue : function(item){
  2490. return this.fields[item].menu.picker.getValue();
  2491. },
  2492. /**
  2493. * Gets the menu picker associated with the passed field
  2494. * @param {String} item The field identifier ('before', 'after', 'on')
  2495. * @return {Object} The menu picker
  2496. */
  2497. getPicker : function(item){
  2498. return this.fields[item].menu.picker;
  2499. },
  2500. /**
  2501. * Template method that is to validate the provided Ext.data.Record
  2502. * against the filters configuration.
  2503. * @param {Ext.data.Record} record The record to validate
  2504. * @return {Boolean} true if the record is valid within the bounds
  2505. * of the filter, false otherwise.
  2506. */
  2507. validateRecord : function (record) {
  2508. var key,
  2509. pickerValue,
  2510. val = record.get(this.dataIndex);
  2511. if(!Ext.isDate(val)){
  2512. return false;
  2513. }
  2514. val = val.clearTime(true).getTime();
  2515. for (key in this.fields) {
  2516. if (this.fields[key].checked) {
  2517. pickerValue = this.getFieldValue(key).clearTime(true).getTime();
  2518. if (key == 'before' && pickerValue <= val) {
  2519. return false;
  2520. }
  2521. if (key == 'after' && pickerValue >= val) {
  2522. return false;
  2523. }
  2524. if (key == 'on' && pickerValue != val) {
  2525. return false;
  2526. }
  2527. }
  2528. }
  2529. return true;
  2530. }
  2531. });/**
  2532. * @class Ext.ux.grid.filter.ListFilter
  2533. * @extends Ext.ux.grid.filter.Filter
  2534. * <p>List filters are able to be preloaded/backed by an Ext.data.Store to load
  2535. * their options the first time they are shown. ListFilter utilizes the
  2536. * {@link Ext.ux.menu.ListMenu} component.</p>
  2537. * <p>Although not shown here, this class accepts all configuration options
  2538. * for {@link Ext.ux.menu.ListMenu}.</p>
  2539. *
  2540. * <p><b><u>Example Usage:</u></b></p>
  2541. * <pre><code>
  2542. var filters = new Ext.ux.grid.GridFilters({
  2543. ...
  2544. filters: [{
  2545. type: 'list',
  2546. dataIndex: 'size',
  2547. phpMode: true,
  2548. // options will be used as data to implicitly creates an ArrayStore
  2549. options: ['extra small', 'small', 'medium', 'large', 'extra large']
  2550. }]
  2551. });
  2552. * </code></pre>
  2553. *
  2554. */
  2555. Ext.ux.grid.filter.ListFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
  2556. /**
  2557. * @cfg {Array} options
  2558. * <p><code>data</code> to be used to implicitly create a data store
  2559. * to back this list when the data source is <b>local</b>. If the
  2560. * data for the list is remote, use the <code>{@link #store}</code>
  2561. * config instead.</p>
  2562. * <br><p>Each item within the provided array may be in one of the
  2563. * following formats:</p>
  2564. * <div class="mdetail-params"><ul>
  2565. * <li><b>Array</b> :
  2566. * <pre><code>
  2567. options: [
  2568. [11, 'extra small'],
  2569. [18, 'small'],
  2570. [22, 'medium'],
  2571. [35, 'large'],
  2572. [44, 'extra large']
  2573. ]
  2574. * </code></pre>
  2575. * </li>
  2576. * <li><b>Object</b> :
  2577. * <pre><code>
  2578. labelField: 'name', // override default of 'text'
  2579. options: [
  2580. {id: 11, name:'extra small'},
  2581. {id: 18, name:'small'},
  2582. {id: 22, name:'medium'},
  2583. {id: 35, name:'large'},
  2584. {id: 44, name:'extra large'}
  2585. ]
  2586. * </code></pre>
  2587. * </li>
  2588. * <li><b>String</b> :
  2589. * <pre><code>
  2590. * options: ['extra small', 'small', 'medium', 'large', 'extra large']
  2591. * </code></pre>
  2592. * </li>
  2593. */
  2594. /**
  2595. * @cfg {Boolean} phpMode
  2596. * <p>Adjust the format of this filter. Defaults to false.</p>
  2597. * <br><p>When GridFilters <code>@cfg encode = false</code> (default):</p>
  2598. * <pre><code>
  2599. // phpMode == false (default):
  2600. filter[0][data][type] list
  2601. filter[0][data][value] value1
  2602. filter[0][data][value] value2
  2603. filter[0][field] prod
  2604. // phpMode == true:
  2605. filter[0][data][type] list
  2606. filter[0][data][value] value1, value2
  2607. filter[0][field] prod
  2608. * </code></pre>
  2609. * When GridFilters <code>@cfg encode = true</code>:
  2610. * <pre><code>
  2611. // phpMode == false (default):
  2612. filter : [{"type":"list","value":["small","medium"],"field":"size"}]
  2613. // phpMode == true:
  2614. filter : [{"type":"list","value":"small,medium","field":"size"}]
  2615. * </code></pre>
  2616. */
  2617. phpMode : false,
  2618. /**
  2619. * @cfg {Ext.data.Store} store
  2620. * The {@link Ext.data.Store} this list should use as its data source
  2621. * when the data source is <b>remote</b>. If the data for the list
  2622. * is local, use the <code>{@link #options}</code> config instead.
  2623. */
  2624. /**
  2625. * @private
  2626. * Template method that is to initialize the filter and install required menu items.
  2627. * @param {Object} config
  2628. */
  2629. init : function (config) {
  2630. this.dt = new Ext.util.DelayedTask(this.fireUpdate, this);
  2631. // if a menu already existed, do clean up first
  2632. if (this.menu){
  2633. this.menu.destroy();
  2634. }
  2635. this.menu = new Ext.ux.menu.ListMenu(config);
  2636. this.menu.on('checkchange', this.onCheckChange, this);
  2637. },
  2638. /**
  2639. * @private
  2640. * Template method that is to get and return the value of the filter.
  2641. * @return {String} The value of this filter
  2642. */
  2643. getValue : function () {
  2644. return this.menu.getSelected();
  2645. },
  2646. /**
  2647. * @private
  2648. * Template method that is to set the value of the filter.
  2649. * @param {Object} value The value to set the filter
  2650. */
  2651. setValue : function (value) {
  2652. this.menu.setSelected(value);
  2653. this.fireEvent('update', this);
  2654. },
  2655. /**
  2656. * @private
  2657. * Template method that is to return <tt>true</tt> if the filter
  2658. * has enough configuration information to be activated.
  2659. * @return {Boolean}
  2660. */
  2661. isActivatable : function () {
  2662. return this.getValue().length > 0;
  2663. },
  2664. /**
  2665. * @private
  2666. * Template method that is to get and return serialized filter data for
  2667. * transmission to the server.
  2668. * @return {Object/Array} An object or collection of objects containing
  2669. * key value pairs representing the current configuration of the filter.
  2670. */
  2671. getSerialArgs : function () {
  2672. var args = {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
  2673. return args;
  2674. },
  2675. /** @private */
  2676. onCheckChange : function(){
  2677. this.dt.delay(this.updateBuffer);
  2678. },
  2679. /**
  2680. * Template method that is to validate the provided Ext.data.Record
  2681. * against the filters configuration.
  2682. * @param {Ext.data.Record} record The record to validate
  2683. * @return {Boolean} true if the record is valid within the bounds
  2684. * of the filter, false otherwise.
  2685. */
  2686. validateRecord : function (record) {
  2687. return this.getValue().indexOf(record.get(this.dataIndex)) > -1;
  2688. }
  2689. });/**
  2690. * @class Ext.ux.grid.filter.NumericFilter
  2691. * @extends Ext.ux.grid.filter.Filter
  2692. * Filters using an Ext.ux.menu.RangeMenu.
  2693. * <p><b><u>Example Usage:</u></b></p>
  2694. * <pre><code>
  2695. var filters = new Ext.ux.grid.GridFilters({
  2696. ...
  2697. filters: [{
  2698. type: 'numeric',
  2699. dataIndex: 'price'
  2700. }]
  2701. });
  2702. * </code></pre>
  2703. */
  2704. Ext.ux.grid.filter.NumericFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
  2705. /**
  2706. * @cfg {Object} fieldCls
  2707. * The Class to use to construct each field item within this menu
  2708. * Defaults to:<pre>
  2709. * fieldCls : Ext.form.NumberField
  2710. * </pre>
  2711. */
  2712. fieldCls : Ext.form.NumberField,
  2713. /**
  2714. * @cfg {Object} fieldCfg
  2715. * The default configuration options for any field item unless superseded
  2716. * by the <code>{@link #fields}</code> configuration.
  2717. * Defaults to:<pre>
  2718. * fieldCfg : {}
  2719. * </pre>
  2720. * Example usage:
  2721. * <pre><code>
  2722. fieldCfg : {
  2723. width: 150,
  2724. },
  2725. * </code></pre>
  2726. */
  2727. /**
  2728. * @cfg {Object} fields
  2729. * The field items may be configured individually
  2730. * Defaults to <tt>undefined</tt>.
  2731. * Example usage:
  2732. * <pre><code>
  2733. fields : {
  2734. gt: { // override fieldCfg options
  2735. width: 200,
  2736. fieldCls: Ext.ux.form.CustomNumberField // to override default {@link #fieldCls}
  2737. }
  2738. },
  2739. * </code></pre>
  2740. */
  2741. /**
  2742. * @cfg {Object} iconCls
  2743. * The iconCls to be applied to each comparator field item.
  2744. * Defaults to:<pre>
  2745. iconCls : {
  2746. gt : 'ux-rangemenu-gt',
  2747. lt : 'ux-rangemenu-lt',
  2748. eq : 'ux-rangemenu-eq'
  2749. }
  2750. * </pre>
  2751. */
  2752. iconCls : {
  2753. gt : 'ux-rangemenu-gt',
  2754. lt : 'ux-rangemenu-lt',
  2755. eq : 'ux-rangemenu-eq'
  2756. },
  2757. /**
  2758. * @cfg {Object} menuItemCfgs
  2759. * Default configuration options for each menu item
  2760. * Defaults to:<pre>
  2761. menuItemCfgs : {
  2762. emptyText: 'Enter Filter Text...',
  2763. selectOnFocus: true,
  2764. width: 125
  2765. }
  2766. * </pre>
  2767. */
  2768. menuItemCfgs : {
  2769. emptyText: 'Enter Filter Text...',
  2770. selectOnFocus: true,
  2771. width: 125
  2772. },
  2773. /**
  2774. * @cfg {Array} menuItems
  2775. * The items to be shown in this menu. Items are added to the menu
  2776. * according to their position within this array. Defaults to:<pre>
  2777. * menuItems : ['lt','gt','-','eq']
  2778. * </pre>
  2779. */
  2780. menuItems : ['lt', 'gt', '-', 'eq'],
  2781. /**
  2782. * @private
  2783. * Template method that is to initialize the filter and install required menu items.
  2784. */
  2785. init : function (config) {
  2786. // if a menu already existed, do clean up first
  2787. if (this.menu){
  2788. this.menu.destroy();
  2789. }
  2790. this.menu = new Ext.ux.menu.RangeMenu(Ext.apply(config, {
  2791. // pass along filter configs to the menu
  2792. fieldCfg : this.fieldCfg || {},
  2793. fieldCls : this.fieldCls,
  2794. fields : this.fields || {},
  2795. iconCls: this.iconCls,
  2796. menuItemCfgs: this.menuItemCfgs,
  2797. menuItems: this.menuItems,
  2798. updateBuffer: this.updateBuffer
  2799. }));
  2800. // relay the event fired by the menu
  2801. this.menu.on('update', this.fireUpdate, this);
  2802. },
  2803. /**
  2804. * @private
  2805. * Template method that is to get and return the value of the filter.
  2806. * @return {String} The value of this filter
  2807. */
  2808. getValue : function () {
  2809. return this.menu.getValue();
  2810. },
  2811. /**
  2812. * @private
  2813. * Template method that is to set the value of the filter.
  2814. * @param {Object} value The value to set the filter
  2815. */
  2816. setValue : function (value) {
  2817. this.menu.setValue(value);
  2818. },
  2819. /**
  2820. * @private
  2821. * Template method that is to return <tt>true</tt> if the filter
  2822. * has enough configuration information to be activated.
  2823. * @return {Boolean}
  2824. */
  2825. isActivatable : function () {
  2826. var values = this.getValue();
  2827. for (key in values) {
  2828. if (values[key] !== undefined) {
  2829. return true;
  2830. }
  2831. }
  2832. return false;
  2833. },
  2834. /**
  2835. * @private
  2836. * Template method that is to get and return serialized filter data for
  2837. * transmission to the server.
  2838. * @return {Object/Array} An object or collection of objects containing
  2839. * key value pairs representing the current configuration of the filter.
  2840. */
  2841. getSerialArgs : function () {
  2842. var key,
  2843. args = [],
  2844. values = this.menu.getValue();
  2845. for (key in values) {
  2846. args.push({
  2847. type: 'numeric',
  2848. comparison: key,
  2849. value: values[key]
  2850. });
  2851. }
  2852. return args;
  2853. },
  2854. /**
  2855. * Template method that is to validate the provided Ext.data.Record
  2856. * against the filters configuration.
  2857. * @param {Ext.data.Record} record The record to validate
  2858. * @return {Boolean} true if the record is valid within the bounds
  2859. * of the filter, false otherwise.
  2860. */
  2861. validateRecord : function (record) {
  2862. var val = record.get(this.dataIndex),
  2863. values = this.getValue();
  2864. if (values.eq !== undefined && val != values.eq) {
  2865. return false;
  2866. }
  2867. if (values.lt !== undefined && val >= values.lt) {
  2868. return false;
  2869. }
  2870. if (values.gt !== undefined && val <= values.gt) {
  2871. return false;
  2872. }
  2873. return true;
  2874. }
  2875. });/**
  2876. * @class Ext.ux.grid.filter.StringFilter
  2877. * @extends Ext.ux.grid.filter.Filter
  2878. * Filter by a configurable Ext.form.TextField
  2879. * <p><b><u>Example Usage:</u></b></p>
  2880. * <pre><code>
  2881. var filters = new Ext.ux.grid.GridFilters({
  2882. ...
  2883. filters: [{
  2884. // required configs
  2885. type: 'string',
  2886. dataIndex: 'name',
  2887. // optional configs
  2888. value: 'foo',
  2889. active: true, // default is false
  2890. iconCls: 'ux-gridfilter-text-icon' // default
  2891. // any Ext.form.TextField configs accepted
  2892. }]
  2893. });
  2894. * </code></pre>
  2895. */
  2896. Ext.ux.grid.filter.StringFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
  2897. /**
  2898. * @cfg {String} iconCls
  2899. * The iconCls to be applied to the menu item.
  2900. * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.
  2901. */
  2902. iconCls : 'ux-gridfilter-text-icon',
  2903. emptyText: 'Enter Filter Text...',
  2904. selectOnFocus: true,
  2905. width: 125,
  2906. /**
  2907. * @private
  2908. * Template method that is to initialize the filter and install required menu items.
  2909. */
  2910. init : function (config) {
  2911. Ext.applyIf(config, {
  2912. enableKeyEvents: true,
  2913. iconCls: this.iconCls,
  2914. listeners: {
  2915. scope: this,
  2916. keyup: this.onInputKeyUp
  2917. }
  2918. });
  2919. this.inputItem = new Ext.form.TextField(config);
  2920. this.menu.add(this.inputItem);
  2921. this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
  2922. },
  2923. /**
  2924. * @private
  2925. * Template method that is to get and return the value of the filter.
  2926. * @return {String} The value of this filter
  2927. */
  2928. getValue : function () {
  2929. return this.inputItem.getValue();
  2930. },
  2931. /**
  2932. * @private
  2933. * Template method that is to set the value of the filter.
  2934. * @param {Object} value The value to set the filter
  2935. */
  2936. setValue : function (value) {
  2937. this.inputItem.setValue(value);
  2938. this.fireEvent('update', this);
  2939. },
  2940. /**
  2941. * @private
  2942. * Template method that is to return <tt>true</tt> if the filter
  2943. * has enough configuration information to be activated.
  2944. * @return {Boolean}
  2945. */
  2946. isActivatable : function () {
  2947. return this.inputItem.getValue().length > 0;
  2948. },
  2949. /**
  2950. * @private
  2951. * Template method that is to get and return serialized filter data for
  2952. * transmission to the server.
  2953. * @return {Object/Array} An object or collection of objects containing
  2954. * key value pairs representing the current configuration of the filter.
  2955. */
  2956. getSerialArgs : function () {
  2957. return {type: 'string', value: this.getValue()};
  2958. },
  2959. /**
  2960. * Template method that is to validate the provided Ext.data.Record
  2961. * against the filters configuration.
  2962. * @param {Ext.data.Record} record The record to validate
  2963. * @return {Boolean} true if the record is valid within the bounds
  2964. * of the filter, false otherwise.
  2965. */
  2966. validateRecord : function (record) {
  2967. var val = record.get(this.dataIndex);
  2968. if(typeof val != 'string') {
  2969. return (this.getValue().length === 0);
  2970. }
  2971. return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;
  2972. },
  2973. /**
  2974. * @private
  2975. * Handler method called when there is a keyup event on this.inputItem
  2976. */
  2977. onInputKeyUp : function (field, e) {
  2978. var k = e.getKey();
  2979. if (k == e.RETURN && field.isValid()) {
  2980. e.stopEvent();
  2981. this.menu.hide(true);
  2982. return;
  2983. }
  2984. // restart the timer
  2985. this.updateTask.delay(this.updateBuffer);
  2986. }
  2987. });
  2988. Ext.namespace('Ext.ux.menu');
  2989. /**
  2990. * @class Ext.ux.menu.ListMenu
  2991. * @extends Ext.menu.Menu
  2992. * This is a supporting class for {@link Ext.ux.grid.filter.ListFilter}.
  2993. * Although not listed as configuration options for this class, this class
  2994. * also accepts all configuration options from {@link Ext.ux.grid.filter.ListFilter}.
  2995. */
  2996. Ext.ux.menu.ListMenu = Ext.extend(Ext.menu.Menu, {
  2997. /**
  2998. * @cfg {String} labelField
  2999. * Defaults to 'text'.
  3000. */
  3001. labelField : 'text',
  3002. /**
  3003. * @cfg {String} paramPrefix
  3004. * Defaults to 'Loading...'.
  3005. */
  3006. loadingText : 'Loading...',
  3007. /**
  3008. * @cfg {Boolean} loadOnShow
  3009. * Defaults to true.
  3010. */
  3011. loadOnShow : true,
  3012. /**
  3013. * @cfg {Boolean} single
  3014. * Specify true to group all items in this list into a single-select
  3015. * radio button group. Defaults to false.
  3016. */
  3017. single : false,
  3018. constructor : function (cfg) {
  3019. this.selected = [];
  3020. this.addEvents(
  3021. /**
  3022. * @event checkchange
  3023. * Fires when there is a change in checked items from this list
  3024. * @param {Object} item Ext.menu.CheckItem
  3025. * @param {Object} checked The checked value that was set
  3026. */
  3027. 'checkchange'
  3028. );
  3029. Ext.ux.menu.ListMenu.superclass.constructor.call(this, cfg = cfg || {});
  3030. if(!cfg.store && cfg.options){
  3031. var options = [];
  3032. for(var i=0, len=cfg.options.length; i<len; i++){
  3033. var value = cfg.options[i];
  3034. switch(Ext.type(value)){
  3035. case 'array': options.push(value); break;
  3036. case 'object': options.push([value.id, value[this.labelField]]); break;
  3037. case 'string': options.push([value, value]); break;
  3038. }
  3039. }
  3040. this.store = new Ext.data.Store({
  3041. reader: new Ext.data.ArrayReader({id: 0}, ['id', this.labelField]),
  3042. data: options,
  3043. listeners: {
  3044. 'load': this.onLoad,
  3045. scope: this
  3046. }
  3047. });
  3048. this.loaded = true;
  3049. } else {
  3050. this.add({text: this.loadingText, iconCls: 'loading-indicator'});
  3051. this.store.on('load', this.onLoad, this);
  3052. }
  3053. },
  3054. destroy : function () {
  3055. if (this.store) {
  3056. this.store.destroy();
  3057. }
  3058. Ext.ux.menu.ListMenu.superclass.destroy.call(this);
  3059. },
  3060. /**
  3061. * Lists will initially show a 'loading' item while the data is retrieved from the store.
  3062. * In some cases the loaded data will result in a list that goes off the screen to the
  3063. * right (as placement calculations were done with the loading item). This adapter will
  3064. * allow show to be called with no arguments to show with the previous arguments and
  3065. * thus recalculate the width and potentially hang the menu from the left.
  3066. */
  3067. show : function () {
  3068. var lastArgs = null;
  3069. return function(){
  3070. if(arguments.length === 0){
  3071. Ext.ux.menu.ListMenu.superclass.show.apply(this, lastArgs);
  3072. } else {
  3073. lastArgs = arguments;
  3074. if (this.loadOnShow && !this.loaded) {
  3075. this.store.load();
  3076. }
  3077. Ext.ux.menu.ListMenu.superclass.show.apply(this, arguments);
  3078. }
  3079. };
  3080. }(),
  3081. /** @private */
  3082. onLoad : function (store, records) {
  3083. var visible = this.isVisible();
  3084. this.hide(false);
  3085. this.removeAll(true);
  3086. var gid = this.single ? Ext.id() : null;
  3087. for(var i=0, len=records.length; i<len; i++){
  3088. var item = new Ext.menu.CheckItem({
  3089. text: records[i].get(this.labelField),
  3090. group: gid,
  3091. checked: this.selected.indexOf(records[i].id) > -1,
  3092. hideOnClick: false});
  3093. item.itemId = records[i].id;
  3094. item.on('checkchange', this.checkChange, this);
  3095. this.add(item);
  3096. }
  3097. this.loaded = true;
  3098. if (visible) {
  3099. this.show();
  3100. }
  3101. this.fireEvent('load', this, records);
  3102. },
  3103. /**
  3104. * Get the selected items.
  3105. * @return {Array} selected
  3106. */
  3107. getSelected : function () {
  3108. return this.selected;
  3109. },
  3110. /** @private */
  3111. setSelected : function (value) {
  3112. value = this.selected = [].concat(value);
  3113. if (this.loaded) {
  3114. this.items.each(function(item){
  3115. item.setChecked(false, true);
  3116. for (var i = 0, len = value.length; i < len; i++) {
  3117. if (item.itemId == value[i]) {
  3118. item.setChecked(true, true);
  3119. }
  3120. }
  3121. }, this);
  3122. }
  3123. },
  3124. /**
  3125. * Handler for the 'checkchange' event from an check item in this menu
  3126. * @param {Object} item Ext.menu.CheckItem
  3127. * @param {Object} checked The checked value that was set
  3128. */
  3129. checkChange : function (item, checked) {
  3130. var value = [];
  3131. this.items.each(function(item){
  3132. if (item.checked) {
  3133. value.push(item.itemId);
  3134. }
  3135. },this);
  3136. this.selected = value;
  3137. this.fireEvent('checkchange', item, checked);
  3138. }
  3139. });Ext.ns('Ext.ux.menu');
  3140. /**
  3141. * @class Ext.ux.menu.RangeMenu
  3142. * @extends Ext.menu.Menu
  3143. * Custom implementation of Ext.menu.Menu that has preconfigured
  3144. * items for gt, lt, eq.
  3145. * <p><b><u>Example Usage:</u></b></p>
  3146. * <pre><code>
  3147. * </code></pre>
  3148. */
  3149. Ext.ux.menu.RangeMenu = Ext.extend(Ext.menu.Menu, {
  3150. constructor : function (config) {
  3151. Ext.ux.menu.RangeMenu.superclass.constructor.call(this, config);
  3152. this.addEvents(
  3153. /**
  3154. * @event update
  3155. * Fires when a filter configuration has changed
  3156. * @param {Ext.ux.grid.filter.Filter} this The filter object.
  3157. */
  3158. 'update'
  3159. );
  3160. this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
  3161. var i, len, item, cfg, Cls;
  3162. for (i = 0, len = this.menuItems.length; i < len; i++) {
  3163. item = this.menuItems[i];
  3164. if (item !== '-') {
  3165. // defaults
  3166. cfg = {
  3167. itemId: 'range-' + item,
  3168. enableKeyEvents: true,
  3169. iconCls: this.iconCls[item] || 'no-icon',
  3170. listeners: {
  3171. scope: this,
  3172. keyup: this.onInputKeyUp
  3173. }
  3174. };
  3175. Ext.apply(
  3176. cfg,
  3177. // custom configs
  3178. Ext.applyIf(this.fields[item] || {}, this.fieldCfg[item]),
  3179. // configurable defaults
  3180. this.menuItemCfgs
  3181. );
  3182. Cls = cfg.fieldCls || this.fieldCls;
  3183. item = this.fields[item] = new Cls(cfg);
  3184. }
  3185. this.add(item);
  3186. }
  3187. },
  3188. /**
  3189. * @private
  3190. * called by this.updateTask
  3191. */
  3192. fireUpdate : function () {
  3193. this.fireEvent('update', this);
  3194. },
  3195. /**
  3196. * Get and return the value of the filter.
  3197. * @return {String} The value of this filter
  3198. */
  3199. getValue : function () {
  3200. var result = {}, key, field;
  3201. for (key in this.fields) {
  3202. field = this.fields[key];
  3203. if (field.isValid() && String(field.getValue()).length > 0) {
  3204. result[key] = field.getValue();
  3205. }
  3206. }
  3207. return result;
  3208. },
  3209. /**
  3210. * Set the value of this menu and fires the 'update' event.
  3211. * @param {Object} data The data to assign to this menu
  3212. */
  3213. setValue : function (data) {
  3214. var key;
  3215. for (key in this.fields) {
  3216. this.fields[key].setValue(data[key] !== undefined ? data[key] : '');
  3217. }
  3218. this.fireEvent('update', this);
  3219. },
  3220. /**
  3221. * @private
  3222. * Handler method called when there is a keyup event on an input
  3223. * item of this menu.
  3224. */
  3225. onInputKeyUp : function (field, e) {
  3226. var k = e.getKey();
  3227. if (k == e.RETURN && field.isValid()) {
  3228. e.stopEvent();
  3229. this.hide(true);
  3230. return;
  3231. }
  3232. if (field == this.fields.eq) {
  3233. if (this.fields.gt) {
  3234. this.fields.gt.setValue(null);
  3235. }
  3236. if (this.fields.lt) {
  3237. this.fields.lt.setValue(null);
  3238. }
  3239. }
  3240. else {
  3241. this.fields.eq.setValue(null);
  3242. }
  3243. // restart the timer
  3244. this.updateTask.delay(this.updateBuffer);
  3245. }
  3246. });
  3247. Ext.ns('Ext.ux.grid');
  3248. /**
  3249. * @class Ext.ux.grid.GroupSummary
  3250. * @extends Ext.util.Observable
  3251. * A GridPanel plugin that enables dynamic column calculations and a dynamically
  3252. * updated grouped summary row.
  3253. */
  3254. Ext.ux.grid.GroupSummary = Ext.extend(Ext.util.Observable, {
  3255. /**
  3256. * @cfg {Function} summaryRenderer Renderer example:<pre><code>
  3257. summaryRenderer: function(v, params, data){
  3258. return ((v === 0 || v > 1) ? '(' + v +' Tasks)' : '(1 Task)');
  3259. },
  3260. * </code></pre>
  3261. */
  3262. /**
  3263. * @cfg {String} summaryType (Optional) The type of
  3264. * calculation to be used for the column. For options available see
  3265. * {@link #Calculations}.
  3266. */
  3267. constructor : function(config){
  3268. Ext.apply(this, config);
  3269. Ext.ux.grid.GroupSummary.superclass.constructor.call(this);
  3270. },
  3271. init : function(grid){
  3272. this.grid = grid;
  3273. var v = this.view = grid.getView();
  3274. v.doGroupEnd = this.doGroupEnd.createDelegate(this);
  3275. v.afterMethod('onColumnWidthUpdated', this.doWidth, this);
  3276. v.afterMethod('onAllColumnWidthsUpdated', this.doAllWidths, this);
  3277. v.afterMethod('onColumnHiddenUpdated', this.doHidden, this);
  3278. v.afterMethod('onUpdate', this.doUpdate, this);
  3279. v.afterMethod('onRemove', this.doRemove, this);
  3280. if(!this.rowTpl){
  3281. this.rowTpl = new Ext.Template(
  3282. '<div class="x-grid3-summary-row" style="{tstyle}">',
  3283. '<table class="x-grid3-summary-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
  3284. '<tbody><tr>{cells}</tr></tbody>',
  3285. '</table></div>'
  3286. );
  3287. this.rowTpl.disableFormats = true;
  3288. }
  3289. this.rowTpl.compile();
  3290. if(!this.cellTpl){
  3291. this.cellTpl = new Ext.Template(
  3292. '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}">',
  3293. '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on">{value}</div>',
  3294. "</td>"
  3295. );
  3296. this.cellTpl.disableFormats = true;
  3297. }
  3298. this.cellTpl.compile();
  3299. },
  3300. /**
  3301. * Toggle the display of the summary row on/off
  3302. * @param {Boolean} visible <tt>true</tt> to show the summary, <tt>false</tt> to hide the summary.
  3303. */
  3304. toggleSummaries : function(visible){
  3305. var el = this.grid.getGridEl();
  3306. if(el){
  3307. if(visible === undefined){
  3308. visible = el.hasClass('x-grid-hide-summary');
  3309. }
  3310. el[visible ? 'removeClass' : 'addClass']('x-grid-hide-summary');
  3311. }
  3312. },
  3313. renderSummary : function(o, cs){
  3314. cs = cs || this.view.getColumnData();
  3315. var cfg = this.grid.getColumnModel().config,
  3316. buf = [], c, p = {}, cf, last = cs.length-1;
  3317. for(var i = 0, len = cs.length; i < len; i++){
  3318. c = cs[i];
  3319. cf = cfg[i];
  3320. p.id = c.id;
  3321. p.style = c.style;
  3322. p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
  3323. if(cf.summaryType || cf.summaryRenderer){
  3324. p.value = (cf.summaryRenderer || c.renderer)(o.data[c.name], p, o);
  3325. }else{
  3326. p.value = '';
  3327. }
  3328. if(p.value == undefined || p.value === "") p.value = "&#160;";
  3329. buf[buf.length] = this.cellTpl.apply(p);
  3330. }
  3331. return this.rowTpl.apply({
  3332. tstyle: 'width:'+this.view.getTotalWidth()+';',
  3333. cells: buf.join('')
  3334. });
  3335. },
  3336. /**
  3337. * @private
  3338. * @param {Object} rs
  3339. * @param {Object} cs
  3340. */
  3341. calculate : function(rs, cs){
  3342. var data = {}, r, c, cfg = this.grid.getColumnModel().config, cf;
  3343. for(var j = 0, jlen = rs.length; j < jlen; j++){
  3344. r = rs[j];
  3345. for(var i = 0, len = cs.length; i < len; i++){
  3346. c = cs[i];
  3347. cf = cfg[i];
  3348. if(cf.summaryType){
  3349. data[c.name] = Ext.ux.grid.GroupSummary.Calculations[cf.summaryType](data[c.name] || 0, r, c.name, data);
  3350. }
  3351. }
  3352. }
  3353. return data;
  3354. },
  3355. doGroupEnd : function(buf, g, cs, ds, colCount){
  3356. var data = this.calculate(g.rs, cs);
  3357. buf.push('</div>', this.renderSummary({data: data}, cs), '</div>');
  3358. },
  3359. doWidth : function(col, w, tw){
  3360. if(!this.isGrouped()){
  3361. return;
  3362. }
  3363. var gs = this.view.getGroups(),
  3364. len = gs.length,
  3365. i = 0,
  3366. s;
  3367. for(; i < len; ++i){
  3368. s = gs[i].childNodes[2];
  3369. s.style.width = tw;
  3370. s.firstChild.style.width = tw;
  3371. s.firstChild.rows[0].childNodes[col].style.width = w;
  3372. }
  3373. },
  3374. doAllWidths : function(ws, tw){
  3375. if(!this.isGrouped()){
  3376. return;
  3377. }
  3378. var gs = this.view.getGroups(),
  3379. len = gs.length,
  3380. i = 0,
  3381. j,
  3382. s,
  3383. cells,
  3384. wlen = ws.length;
  3385. for(; i < len; i++){
  3386. s = gs[i].childNodes[2];
  3387. s.style.width = tw;
  3388. s.firstChild.style.width = tw;
  3389. cells = s.firstChild.rows[0].childNodes;
  3390. for(j = 0; j < wlen; j++){
  3391. cells[j].style.width = ws[j];
  3392. }
  3393. }
  3394. },
  3395. doHidden : function(col, hidden, tw){
  3396. if(!this.isGrouped()){
  3397. return;
  3398. }
  3399. var gs = this.view.getGroups(),
  3400. len = gs.length,
  3401. i = 0,
  3402. s,
  3403. display = hidden ? 'none' : '';
  3404. for(; i < len; i++){
  3405. s = gs[i].childNodes[2];
  3406. s.style.width = tw;
  3407. s.firstChild.style.width = tw;
  3408. s.firstChild.rows[0].childNodes[col].style.display = display;
  3409. }
  3410. },
  3411. isGrouped : function(){
  3412. return !Ext.isEmpty(this.grid.getStore().groupField);
  3413. },
  3414. // Note: requires that all (or the first) record in the
  3415. // group share the same group value. Returns false if the group
  3416. // could not be found.
  3417. refreshSummary : function(groupValue){
  3418. return this.refreshSummaryById(this.view.getGroupId(groupValue));
  3419. },
  3420. getSummaryNode : function(gid){
  3421. var g = Ext.fly(gid, '_gsummary');
  3422. if(g){
  3423. return g.down('.x-grid3-summary-row', true);
  3424. }
  3425. return null;
  3426. },
  3427. refreshSummaryById : function(gid){
  3428. var g = Ext.getDom(gid);
  3429. if(!g){
  3430. return false;
  3431. }
  3432. var rs = [];
  3433. this.grid.getStore().each(function(r){
  3434. if(r._groupId == gid){
  3435. rs[rs.length] = r;
  3436. }
  3437. });
  3438. var cs = this.view.getColumnData(),
  3439. data = this.calculate(rs, cs),
  3440. markup = this.renderSummary({data: data}, cs),
  3441. existing = this.getSummaryNode(gid);
  3442. if(existing){
  3443. g.removeChild(existing);
  3444. }
  3445. Ext.DomHelper.append(g, markup);
  3446. return true;
  3447. },
  3448. doUpdate : function(ds, record){
  3449. this.refreshSummaryById(record._groupId);
  3450. },
  3451. doRemove : function(ds, record, index, isUpdate){
  3452. if(!isUpdate){
  3453. this.refreshSummaryById(record._groupId);
  3454. }
  3455. },
  3456. /**
  3457. * Show a message in the summary row.
  3458. * <pre><code>
  3459. grid.on('afteredit', function(){
  3460. var groupValue = 'Ext Forms: Field Anchoring';
  3461. summary.showSummaryMsg(groupValue, 'Updating Summary...');
  3462. });
  3463. * </code></pre>
  3464. * @param {String} groupValue
  3465. * @param {String} msg Text to use as innerHTML for the summary row.
  3466. */
  3467. showSummaryMsg : function(groupValue, msg){
  3468. var gid = this.view.getGroupId(groupValue),
  3469. node = this.getSummaryNode(gid);
  3470. if(node){
  3471. node.innerHTML = '<div class="x-grid3-summary-msg">' + msg + '</div>';
  3472. }
  3473. }
  3474. });
  3475. //backwards compat
  3476. Ext.grid.GroupSummary = Ext.ux.grid.GroupSummary;
  3477. /**
  3478. * Calculation types for summary row:</p><div class="mdetail-params"><ul>
  3479. * <li><b><tt>sum</tt></b> : <div class="sub-desc"></div></li>
  3480. * <li><b><tt>count</tt></b> : <div class="sub-desc"></div></li>
  3481. * <li><b><tt>max</tt></b> : <div class="sub-desc"></div></li>
  3482. * <li><b><tt>min</tt></b> : <div class="sub-desc"></div></li>
  3483. * <li><b><tt>average</tt></b> : <div class="sub-desc"></div></li>
  3484. * </ul></div>
  3485. * <p>Custom calculations may be implemented. An example of
  3486. * custom <code>summaryType=totalCost</code>:</p><pre><code>
  3487. // define a custom summary function
  3488. Ext.ux.grid.GroupSummary.Calculations['totalCost'] = function(v, record, field){
  3489. return v + (record.data.estimate * record.data.rate);
  3490. };
  3491. * </code></pre>
  3492. * @property Calculations
  3493. */
  3494. Ext.ux.grid.GroupSummary.Calculations = {
  3495. 'sum' : function(v, record, field){
  3496. return v + (record.data[field]||0);
  3497. },
  3498. 'count' : function(v, record, field, data){
  3499. return data[field+'count'] ? ++data[field+'count'] : (data[field+'count'] = 1);
  3500. },
  3501. 'max' : function(v, record, field, data){
  3502. var v = record.data[field];
  3503. var max = data[field+'max'] === undefined ? (data[field+'max'] = v) : data[field+'max'];
  3504. return v > max ? (data[field+'max'] = v) : max;
  3505. },
  3506. 'min' : function(v, record, field, data){
  3507. var v = record.data[field];
  3508. var min = data[field+'min'] === undefined ? (data[field+'min'] = v) : data[field+'min'];
  3509. return v < min ? (data[field+'min'] = v) : min;
  3510. },
  3511. 'average' : function(v, record, field, data){
  3512. var c = data[field+'count'] ? ++data[field+'count'] : (data[field+'count'] = 1);
  3513. var t = (data[field+'total'] = ((data[field+'total']||0) + (record.data[field]||0)));
  3514. return t === 0 ? 0 : t / c;
  3515. }
  3516. };
  3517. Ext.grid.GroupSummary.Calculations = Ext.ux.grid.GroupSummary.Calculations;
  3518. /**
  3519. * @class Ext.ux.grid.HybridSummary
  3520. * @extends Ext.ux.grid.GroupSummary
  3521. * Adds capability to specify the summary data for the group via json as illustrated here:
  3522. * <pre><code>
  3523. {
  3524. data: [
  3525. {
  3526. projectId: 100, project: 'House',
  3527. taskId: 112, description: 'Paint',
  3528. estimate: 6, rate: 150,
  3529. due:'06/24/2007'
  3530. },
  3531. ...
  3532. ],
  3533. summaryData: {
  3534. 'House': {
  3535. description: 14, estimate: 9,
  3536. rate: 99, due: new Date(2009, 6, 29),
  3537. cost: 999
  3538. }
  3539. }
  3540. }
  3541. * </code></pre>
  3542. *
  3543. */
  3544. Ext.ux.grid.HybridSummary = Ext.extend(Ext.ux.grid.GroupSummary, {
  3545. /**
  3546. * @private
  3547. * @param {Object} rs
  3548. * @param {Object} cs
  3549. */
  3550. calculate : function(rs, cs){
  3551. var gcol = this.view.getGroupField(),
  3552. gvalue = rs[0].data[gcol],
  3553. gdata = this.getSummaryData(gvalue);
  3554. return gdata || Ext.ux.grid.HybridSummary.superclass.calculate.call(this, rs, cs);
  3555. },
  3556. /**
  3557. * <pre><code>
  3558. grid.on('afteredit', function(){
  3559. var groupValue = 'Ext Forms: Field Anchoring';
  3560. summary.showSummaryMsg(groupValue, 'Updating Summary...');
  3561. setTimeout(function(){ // simulate server call
  3562. // HybridSummary class implements updateSummaryData
  3563. summary.updateSummaryData(groupValue,
  3564. // create data object based on configured dataIndex
  3565. {description: 22, estimate: 888, rate: 888, due: new Date(), cost: 8});
  3566. }, 2000);
  3567. });
  3568. * </code></pre>
  3569. * @param {String} groupValue
  3570. * @param {Object} data data object
  3571. * @param {Boolean} skipRefresh (Optional) Defaults to false
  3572. */
  3573. updateSummaryData : function(groupValue, data, skipRefresh){
  3574. var json = this.grid.getStore().reader.jsonData;
  3575. if(!json.summaryData){
  3576. json.summaryData = {};
  3577. }
  3578. json.summaryData[groupValue] = data;
  3579. if(!skipRefresh){
  3580. this.refreshSummary(groupValue);
  3581. }
  3582. },
  3583. /**
  3584. * Returns the summaryData for the specified groupValue or null.
  3585. * @param {String} groupValue
  3586. * @return {Object} summaryData
  3587. */
  3588. getSummaryData : function(groupValue){
  3589. var reader = this.grid.getStore().reader,
  3590. json = reader.jsonData,
  3591. fields = reader.recordType.prototype.fields,
  3592. v;
  3593. if(json && json.summaryData){
  3594. v = json.summaryData[groupValue];
  3595. if(v){
  3596. return reader.extractValues(v, fields.items, fields.length);
  3597. }
  3598. }
  3599. return null;
  3600. }
  3601. });
  3602. //backwards compat
  3603. Ext.grid.HybridSummary = Ext.ux.grid.HybridSummary;
  3604. Ext.ux.GroupTab = Ext.extend(Ext.Container, {
  3605. mainItem: 0,
  3606. expanded: true,
  3607. deferredRender: true,
  3608. activeTab: null,
  3609. idDelimiter: '__',
  3610. headerAsText: false,
  3611. frame: false,
  3612. hideBorders: true,
  3613. initComponent: function(config){
  3614. Ext.apply(this, config);
  3615. this.frame = false;
  3616. Ext.ux.GroupTab.superclass.initComponent.call(this);
  3617. this.addEvents('activate', 'deactivate', 'changemainitem', 'beforetabchange', 'tabchange');
  3618. this.setLayout(new Ext.layout.CardLayout({
  3619. deferredRender: this.deferredRender
  3620. }));
  3621. if (!this.stack) {
  3622. this.stack = Ext.TabPanel.AccessStack();
  3623. }
  3624. this.initItems();
  3625. this.on('beforerender', function(){
  3626. this.groupEl = this.ownerCt.getGroupEl(this);
  3627. }, this);
  3628. this.on('add', this.onAdd, this, {
  3629. target: this
  3630. });
  3631. this.on('remove', this.onRemove, this, {
  3632. target: this
  3633. });
  3634. if (this.mainItem !== undefined) {
  3635. var item = (typeof this.mainItem == 'object') ? this.mainItem : this.items.get(this.mainItem);
  3636. delete this.mainItem;
  3637. this.setMainItem(item);
  3638. }
  3639. },
  3640. /**
  3641. * Sets the specified tab as the active tab. This method fires the {@link #beforetabchange} event which
  3642. * can return false to cancel the tab change.
  3643. * @param {String/Panel} tab The id or tab Panel to activate
  3644. */
  3645. setActiveTab : function(item){
  3646. item = this.getComponent(item);
  3647. if(!item){
  3648. return false;
  3649. }
  3650. if(!this.rendered){
  3651. this.activeTab = item;
  3652. return true;
  3653. }
  3654. if(this.activeTab != item && this.fireEvent('beforetabchange', this, item, this.activeTab) !== false){
  3655. if(this.activeTab && this.activeTab != this.mainItem){
  3656. var oldEl = this.getTabEl(this.activeTab);
  3657. if(oldEl){
  3658. Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
  3659. }
  3660. }
  3661. var el = this.getTabEl(item);
  3662. Ext.fly(el).addClass('x-grouptabs-strip-active');
  3663. this.activeTab = item;
  3664. this.stack.add(item);
  3665. this.layout.setActiveItem(item);
  3666. if(this.layoutOnTabChange && item.doLayout){
  3667. item.doLayout();
  3668. }
  3669. if(this.scrolling){
  3670. this.scrollToTab(item, this.animScroll);
  3671. }
  3672. this.fireEvent('tabchange', this, item);
  3673. return true;
  3674. }
  3675. return false;
  3676. },
  3677. getTabEl: function(item){
  3678. if (item == this.mainItem) {
  3679. return this.groupEl;
  3680. }
  3681. return Ext.TabPanel.prototype.getTabEl.call(this, item);
  3682. },
  3683. onRender: function(ct, position){
  3684. Ext.ux.GroupTab.superclass.onRender.call(this, ct, position);
  3685. this.strip = Ext.fly(this.groupEl).createChild({
  3686. tag: 'ul',
  3687. cls: 'x-grouptabs-sub'
  3688. });
  3689. this.tooltip = new Ext.ToolTip({
  3690. target: this.groupEl,
  3691. delegate: 'a.x-grouptabs-text',
  3692. trackMouse: true,
  3693. renderTo: document.body,
  3694. listeners: {
  3695. beforeshow: function(tip) {
  3696. var item = (tip.triggerElement.parentNode === this.mainItem.tabEl)
  3697. ? this.mainItem
  3698. : this.findById(tip.triggerElement.parentNode.id.split(this.idDelimiter)[1]);
  3699. if(!item.tabTip) {
  3700. return false;
  3701. }
  3702. tip.body.dom.innerHTML = item.tabTip;
  3703. },
  3704. scope: this
  3705. }
  3706. });
  3707. if (!this.itemTpl) {
  3708. var tt = new Ext.Template('<li class="{cls}" id="{id}">', '<a onclick="return false;" class="x-grouptabs-text {iconCls}">{text}</a>', '</li>');
  3709. tt.disableFormats = true;
  3710. tt.compile();
  3711. Ext.ux.GroupTab.prototype.itemTpl = tt;
  3712. }
  3713. this.items.each(this.initTab, this);
  3714. },
  3715. afterRender: function(){
  3716. Ext.ux.GroupTab.superclass.afterRender.call(this);
  3717. if (this.activeTab !== undefined) {
  3718. var item = (typeof this.activeTab == 'object') ? this.activeTab : this.items.get(this.activeTab);
  3719. delete this.activeTab;
  3720. this.setActiveTab(item);
  3721. }
  3722. },
  3723. // private
  3724. initTab: function(item, index){
  3725. var before = this.strip.dom.childNodes[index];
  3726. var p = Ext.TabPanel.prototype.getTemplateArgs.call(this, item);
  3727. if (item === this.mainItem) {
  3728. item.tabEl = this.groupEl;
  3729. p.cls += ' x-grouptabs-main-item';
  3730. }
  3731. var el = before ? this.itemTpl.insertBefore(before, p) : this.itemTpl.append(this.strip, p);
  3732. item.tabEl = item.tabEl || el;
  3733. item.on('disable', this.onItemDisabled, this);
  3734. item.on('enable', this.onItemEnabled, this);
  3735. item.on('titlechange', this.onItemTitleChanged, this);
  3736. item.on('iconchange', this.onItemIconChanged, this);
  3737. item.on('beforeshow', this.onBeforeShowItem, this);
  3738. },
  3739. setMainItem: function(item){
  3740. item = this.getComponent(item);
  3741. if (!item || this.fireEvent('changemainitem', this, item, this.mainItem) === false) {
  3742. return;
  3743. }
  3744. this.mainItem = item;
  3745. },
  3746. getMainItem: function(){
  3747. return this.mainItem || null;
  3748. },
  3749. // private
  3750. onBeforeShowItem: function(item){
  3751. if (item != this.activeTab) {
  3752. this.setActiveTab(item);
  3753. return false;
  3754. }
  3755. },
  3756. // private
  3757. onAdd: function(gt, item, index){
  3758. if (this.rendered) {
  3759. this.initTab.call(this, item, index);
  3760. }
  3761. },
  3762. // private
  3763. onRemove: function(tp, item){
  3764. Ext.destroy(Ext.get(this.getTabEl(item)));
  3765. this.stack.remove(item);
  3766. item.un('disable', this.onItemDisabled, this);
  3767. item.un('enable', this.onItemEnabled, this);
  3768. item.un('titlechange', this.onItemTitleChanged, this);
  3769. item.un('iconchange', this.onItemIconChanged, this);
  3770. item.un('beforeshow', this.onBeforeShowItem, this);
  3771. if (item == this.activeTab) {
  3772. var next = this.stack.next();
  3773. if (next) {
  3774. this.setActiveTab(next);
  3775. }
  3776. else if (this.items.getCount() > 0) {
  3777. this.setActiveTab(0);
  3778. }
  3779. else {
  3780. this.activeTab = null;
  3781. }
  3782. }
  3783. },
  3784. // private
  3785. onBeforeAdd: function(item){
  3786. var existing = item.events ? (this.items.containsKey(item.getItemId()) ? item : null) : this.items.get(item);
  3787. if (existing) {
  3788. this.setActiveTab(item);
  3789. return false;
  3790. }
  3791. Ext.TabPanel.superclass.onBeforeAdd.apply(this, arguments);
  3792. var es = item.elements;
  3793. item.elements = es ? es.replace(',header', '') : es;
  3794. item.border = (item.border === true);
  3795. },
  3796. // private
  3797. onItemDisabled: Ext.TabPanel.prototype.onItemDisabled,
  3798. onItemEnabled: Ext.TabPanel.prototype.onItemEnabled,
  3799. // private
  3800. onItemTitleChanged: function(item){
  3801. var el = this.getTabEl(item);
  3802. if (el) {
  3803. Ext.fly(el).child('a.x-grouptabs-text', true).innerHTML = item.title;
  3804. }
  3805. },
  3806. //private
  3807. onItemIconChanged: function(item, iconCls, oldCls){
  3808. var el = this.getTabEl(item);
  3809. if (el) {
  3810. Ext.fly(el).child('a.x-grouptabs-text').replaceClass(oldCls, iconCls);
  3811. }
  3812. },
  3813. beforeDestroy: function(){
  3814. Ext.TabPanel.prototype.beforeDestroy.call(this);
  3815. this.tooltip.destroy();
  3816. }
  3817. });
  3818. Ext.reg('grouptab', Ext.ux.GroupTab);
  3819. Ext.ns('Ext.ux');
  3820. Ext.ux.GroupTabPanel = Ext.extend(Ext.TabPanel, {
  3821. tabPosition: 'left',
  3822. alternateColor: false,
  3823. alternateCls: 'x-grouptabs-panel-alt',
  3824. defaultType: 'grouptab',
  3825. deferredRender: false,
  3826. activeGroup : null,
  3827. initComponent: function(){
  3828. Ext.ux.GroupTabPanel.superclass.initComponent.call(this);
  3829. this.addEvents(
  3830. 'beforegroupchange',
  3831. 'groupchange'
  3832. );
  3833. this.elements = 'body,header';
  3834. this.stripTarget = 'header';
  3835. this.tabPosition = this.tabPosition == 'right' ? 'right' : 'left';
  3836. this.addClass('x-grouptabs-panel');
  3837. if (this.tabStyle && this.tabStyle != '') {
  3838. this.addClass('x-grouptabs-panel-' + this.tabStyle);
  3839. }
  3840. if (this.alternateColor) {
  3841. this.addClass(this.alternateCls);
  3842. }
  3843. this.on('beforeadd', function(gtp, item, index){
  3844. this.initGroup(item, index);
  3845. });
  3846. this.items.each(function(item){
  3847. item.on('tabchange',function(item){
  3848. this.fireEvent('tabchange', this, item.activeTab);
  3849. }, this);
  3850. },this);
  3851. },
  3852. initEvents : function() {
  3853. this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);
  3854. },
  3855. onRender: function(ct, position){
  3856. Ext.TabPanel.superclass.onRender.call(this, ct, position);
  3857. if(this.plain){
  3858. var pos = this.tabPosition == 'top' ? 'header' : 'footer';
  3859. this[pos].addClass('x-tab-panel-'+pos+'-plain');
  3860. }
  3861. var st = this[this.stripTarget];
  3862. this.stripWrap = st.createChild({cls:'x-tab-strip-wrap ', cn:{
  3863. tag:'ul', cls:'x-grouptabs-strip x-grouptabs-tab-strip-'+this.tabPosition}});
  3864. var beforeEl = (this.tabPosition=='bottom' ? this.stripWrap : null);
  3865. this.strip = new Ext.Element(this.stripWrap.dom.firstChild);
  3866. this.header.addClass('x-grouptabs-panel-header');
  3867. this.bwrap.addClass('x-grouptabs-bwrap');
  3868. this.body.addClass('x-tab-panel-body-'+this.tabPosition + ' x-grouptabs-panel-body');
  3869. if (!this.groupTpl) {
  3870. var tt = new Ext.Template(
  3871. '<li class="{cls}" id="{id}">',
  3872. '<a class="x-grouptabs-expand" onclick="return false;"></a>',
  3873. '<a class="x-grouptabs-text {iconCls}" href="#" onclick="return false;">',
  3874. '<span>{text}</span></a>',
  3875. '</li>'
  3876. );
  3877. tt.disableFormats = true;
  3878. tt.compile();
  3879. Ext.ux.GroupTabPanel.prototype.groupTpl = tt;
  3880. }
  3881. this.items.each(this.initGroup, this);
  3882. },
  3883. afterRender: function(){
  3884. Ext.ux.GroupTabPanel.superclass.afterRender.call(this);
  3885. this.tabJoint = Ext.fly(this.body.dom.parentNode).createChild({
  3886. cls: 'x-tab-joint'
  3887. });
  3888. this.addClass('x-tab-panel-' + this.tabPosition);
  3889. this.header.setWidth(this.tabWidth);
  3890. if (this.activeGroup !== undefined) {
  3891. var group = (typeof this.activeGroup == 'object') ? this.activeGroup : this.items.get(this.activeGroup);
  3892. delete this.activeGroup;
  3893. this.setActiveGroup(group);
  3894. group.setActiveTab(group.getMainItem());
  3895. }
  3896. },
  3897. getGroupEl : Ext.TabPanel.prototype.getTabEl,
  3898. // private
  3899. findTargets: function(e){
  3900. var item = null,
  3901. itemEl = e.getTarget('li', this.strip);
  3902. if (itemEl) {
  3903. item = this.findById(itemEl.id.split(this.idDelimiter)[1]);
  3904. if (item.disabled) {
  3905. return {
  3906. expand: null,
  3907. item: null,
  3908. el: null
  3909. };
  3910. }
  3911. }
  3912. return {
  3913. expand: e.getTarget('.x-grouptabs-expand', this.strip),
  3914. isGroup: !e.getTarget('ul.x-grouptabs-sub', this.strip),
  3915. item: item,
  3916. el: itemEl
  3917. };
  3918. },
  3919. // private
  3920. onStripMouseDown: function(e){
  3921. if (e.button != 0) {
  3922. return;
  3923. }
  3924. e.preventDefault();
  3925. var t = this.findTargets(e);
  3926. if (t.expand) {
  3927. this.toggleGroup(t.el);
  3928. }
  3929. else if (t.item) {
  3930. if(t.isGroup) {
  3931. t.item.setActiveTab(t.item.getMainItem());
  3932. }
  3933. else {
  3934. t.item.ownerCt.setActiveTab(t.item);
  3935. }
  3936. }
  3937. },
  3938. expandGroup: function(groupEl){
  3939. if(groupEl.isXType) {
  3940. groupEl = this.getGroupEl(groupEl);
  3941. }
  3942. Ext.fly(groupEl).addClass('x-grouptabs-expanded');
  3943. this.syncTabJoint();
  3944. },
  3945. toggleGroup: function(groupEl){
  3946. if(groupEl.isXType) {
  3947. groupEl = this.getGroupEl(groupEl);
  3948. }
  3949. Ext.fly(groupEl).toggleClass('x-grouptabs-expanded');
  3950. this.syncTabJoint();
  3951. },
  3952. collapseGroup: function(groupEl){
  3953. if(groupEl.isXType) {
  3954. groupEl = this.getGroupEl(groupEl);
  3955. }
  3956. Ext.fly(groupEl).removeClass('x-grouptabs-expanded');
  3957. this.syncTabJoint();
  3958. },
  3959. syncTabJoint: function(groupEl){
  3960. if (!this.tabJoint) {
  3961. return;
  3962. }
  3963. groupEl = groupEl || this.getGroupEl(this.activeGroup);
  3964. if(groupEl) {
  3965. this.tabJoint.setHeight(Ext.fly(groupEl).getHeight() - 2);
  3966. var y = Ext.isGecko2 ? 0 : 1;
  3967. if (this.tabPosition == 'left'){
  3968. this.tabJoint.alignTo(groupEl, 'tl-tr', [-2,y]);
  3969. }
  3970. else {
  3971. this.tabJoint.alignTo(groupEl, 'tr-tl', [1,y]);
  3972. }
  3973. }
  3974. else {
  3975. this.tabJoint.hide();
  3976. }
  3977. },
  3978. getActiveTab : function() {
  3979. if(!this.activeGroup) return null;
  3980. return this.activeGroup.getTabEl(this.activeGroup.activeTab) || null;
  3981. },
  3982. onResize: function(){
  3983. Ext.ux.GroupTabPanel.superclass.onResize.apply(this, arguments);
  3984. this.syncTabJoint();
  3985. },
  3986. createCorner: function(el, pos){
  3987. return Ext.fly(el).createChild({
  3988. cls: 'x-grouptabs-corner x-grouptabs-corner-' + pos
  3989. });
  3990. },
  3991. initGroup: function(group, index){
  3992. var before = this.strip.dom.childNodes[index],
  3993. p = this.getTemplateArgs(group);
  3994. if (index === 0) {
  3995. p.cls += ' x-tab-first';
  3996. }
  3997. p.cls += ' x-grouptabs-main';
  3998. p.text = group.getMainItem().title;
  3999. var el = before ? this.groupTpl.insertBefore(before, p) : this.groupTpl.append(this.strip, p),
  4000. tl = this.createCorner(el, 'top-' + this.tabPosition),
  4001. bl = this.createCorner(el, 'bottom-' + this.tabPosition);
  4002. group.tabEl = el;
  4003. if (group.expanded) {
  4004. this.expandGroup(el);
  4005. }
  4006. if (Ext.isIE6 || (Ext.isIE && !Ext.isStrict)){
  4007. bl.setLeft('-10px');
  4008. bl.setBottom('-5px');
  4009. tl.setLeft('-10px');
  4010. tl.setTop('-5px');
  4011. }
  4012. this.mon(group, {
  4013. scope: this,
  4014. changemainitem: this.onGroupChangeMainItem,
  4015. beforetabchange: this.onGroupBeforeTabChange
  4016. });
  4017. },
  4018. setActiveGroup : function(group) {
  4019. group = this.getComponent(group);
  4020. if(!group){
  4021. return false;
  4022. }
  4023. if(!this.rendered){
  4024. this.activeGroup = group;
  4025. return true;
  4026. }
  4027. if(this.activeGroup != group && this.fireEvent('beforegroupchange', this, group, this.activeGroup) !== false){
  4028. if(this.activeGroup){
  4029. this.activeGroup.activeTab = null;
  4030. var oldEl = this.getGroupEl(this.activeGroup);
  4031. if(oldEl){
  4032. Ext.fly(oldEl).removeClass('x-grouptabs-strip-active');
  4033. }
  4034. }
  4035. var groupEl = this.getGroupEl(group);
  4036. Ext.fly(groupEl).addClass('x-grouptabs-strip-active');
  4037. this.activeGroup = group;
  4038. this.stack.add(group);
  4039. this.layout.setActiveItem(group);
  4040. this.syncTabJoint(groupEl);
  4041. this.fireEvent('groupchange', this, group);
  4042. return true;
  4043. }
  4044. return false;
  4045. },
  4046. onGroupBeforeTabChange: function(group, newTab, oldTab){
  4047. if(group !== this.activeGroup || newTab !== oldTab) {
  4048. this.strip.select('.x-grouptabs-sub > li.x-grouptabs-strip-active', true).removeClass('x-grouptabs-strip-active');
  4049. }
  4050. this.expandGroup(this.getGroupEl(group));
  4051. if(group !== this.activeGroup) {
  4052. return this.setActiveGroup(group);
  4053. }
  4054. },
  4055. getFrameHeight: function(){
  4056. var h = this.el.getFrameWidth('tb');
  4057. h += (this.tbar ? this.tbar.getHeight() : 0) +
  4058. (this.bbar ? this.bbar.getHeight() : 0);
  4059. return h;
  4060. },
  4061. adjustBodyWidth: function(w){
  4062. return w - this.tabWidth;
  4063. }
  4064. });
  4065. Ext.reg('grouptabpanel', Ext.ux.GroupTabPanel);
  4066. /*
  4067. * Note that this control will most likely remain as an example, and not as a core Ext form
  4068. * control. However, the API will be changing in a future release and so should not yet be
  4069. * treated as a final, stable API at this time.
  4070. */
  4071. /**
  4072. * @class Ext.ux.form.ItemSelector
  4073. * @extends Ext.form.Field
  4074. * A control that allows selection of between two Ext.ux.form.MultiSelect controls.
  4075. *
  4076. * @history
  4077. * 2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
  4078. *
  4079. * @constructor
  4080. * Create a new ItemSelector
  4081. * @param {Object} config Configuration options
  4082. * @xtype itemselector
  4083. */
  4084. Ext.ux.form.ItemSelector = Ext.extend(Ext.form.Field, {
  4085. hideNavIcons:false,
  4086. imagePath:"",
  4087. iconUp:"up2.gif",
  4088. iconDown:"down2.gif",
  4089. iconLeft:"left2.gif",
  4090. iconRight:"right2.gif",
  4091. iconTop:"top2.gif",
  4092. iconBottom:"bottom2.gif",
  4093. drawUpIcon:true,
  4094. drawDownIcon:true,
  4095. drawLeftIcon:true,
  4096. drawRightIcon:true,
  4097. drawTopIcon:true,
  4098. drawBotIcon:true,
  4099. delimiter:',',
  4100. bodyStyle:null,
  4101. border:false,
  4102. defaultAutoCreate:{tag: "div"},
  4103. /**
  4104. * @cfg {Array} multiselects An array of {@link Ext.ux.form.MultiSelect} config objects, with at least all required parameters (e.g., store)
  4105. */
  4106. multiselects:null,
  4107. initComponent: function(){
  4108. Ext.ux.form.ItemSelector.superclass.initComponent.call(this);
  4109. this.addEvents({
  4110. 'rowdblclick' : true,
  4111. 'change' : true
  4112. });
  4113. },
  4114. onRender: function(ct, position){
  4115. Ext.ux.form.ItemSelector.superclass.onRender.call(this, ct, position);
  4116. // Internal default configuration for both multiselects
  4117. var msConfig = [{
  4118. legend: 'Available',
  4119. draggable: true,
  4120. droppable: true,
  4121. width: 100,
  4122. height: 100
  4123. },{
  4124. legend: 'Selected',
  4125. droppable: true,
  4126. draggable: true,
  4127. width: 100,
  4128. height: 100
  4129. }];
  4130. this.fromMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[0], msConfig[0]));
  4131. this.fromMultiselect.on('dblclick', this.onRowDblClick, this);
  4132. this.toMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[1], msConfig[1]));
  4133. this.toMultiselect.on('dblclick', this.onRowDblClick, this);
  4134. var p = new Ext.Panel({
  4135. bodyStyle:this.bodyStyle,
  4136. border:this.border,
  4137. layout:"table",
  4138. layoutConfig:{columns:3}
  4139. });
  4140. p.add(this.fromMultiselect);
  4141. var icons = new Ext.Panel({header:false});
  4142. p.add(icons);
  4143. p.add(this.toMultiselect);
  4144. p.render(this.el);
  4145. icons.el.down('.'+icons.bwrapCls).remove();
  4146. // ICON HELL!!!
  4147. if (this.imagePath!="" && this.imagePath.charAt(this.imagePath.length-1)!="/")
  4148. this.imagePath+="/";
  4149. this.iconUp = this.imagePath + (this.iconUp || 'up2.gif');
  4150. this.iconDown = this.imagePath + (this.iconDown || 'down2.gif');
  4151. this.iconLeft = this.imagePath + (this.iconLeft || 'left2.gif');
  4152. this.iconRight = this.imagePath + (this.iconRight || 'right2.gif');
  4153. this.iconTop = this.imagePath + (this.iconTop || 'top2.gif');
  4154. this.iconBottom = this.imagePath + (this.iconBottom || 'bottom2.gif');
  4155. var el=icons.getEl();
  4156. this.toTopIcon = el.createChild({tag:'img', src:this.iconTop, style:{cursor:'pointer', margin:'2px'}});
  4157. el.createChild({tag: 'br'});
  4158. this.upIcon = el.createChild({tag:'img', src:this.iconUp, style:{cursor:'pointer', margin:'2px'}});
  4159. el.createChild({tag: 'br'});
  4160. this.addIcon = el.createChild({tag:'img', src:this.iconRight, style:{cursor:'pointer', margin:'2px'}});
  4161. el.createChild({tag: 'br'});
  4162. this.removeIcon = el.createChild({tag:'img', src:this.iconLeft, style:{cursor:'pointer', margin:'2px'}});
  4163. el.createChild({tag: 'br'});
  4164. this.downIcon = el.createChild({tag:'img', src:this.iconDown, style:{cursor:'pointer', margin:'2px'}});
  4165. el.createChild({tag: 'br'});
  4166. this.toBottomIcon = el.createChild({tag:'img', src:this.iconBottom, style:{cursor:'pointer', margin:'2px'}});
  4167. this.toTopIcon.on('click', this.toTop, this);
  4168. this.upIcon.on('click', this.up, this);
  4169. this.downIcon.on('click', this.down, this);
  4170. this.toBottomIcon.on('click', this.toBottom, this);
  4171. this.addIcon.on('click', this.fromTo, this);
  4172. this.removeIcon.on('click', this.toFrom, this);
  4173. if (!this.drawUpIcon || this.hideNavIcons) { this.upIcon.dom.style.display='none'; }
  4174. if (!this.drawDownIcon || this.hideNavIcons) { this.downIcon.dom.style.display='none'; }
  4175. if (!this.drawLeftIcon || this.hideNavIcons) { this.addIcon.dom.style.display='none'; }
  4176. if (!this.drawRightIcon || this.hideNavIcons) { this.removeIcon.dom.style.display='none'; }
  4177. if (!this.drawTopIcon || this.hideNavIcons) { this.toTopIcon.dom.style.display='none'; }
  4178. if (!this.drawBotIcon || this.hideNavIcons) { this.toBottomIcon.dom.style.display='none'; }
  4179. var tb = p.body.first();
  4180. this.el.setWidth(p.body.first().getWidth());
  4181. p.body.removeClass();
  4182. this.hiddenName = this.name;
  4183. var hiddenTag = {tag: "input", type: "hidden", value: "", name: this.name};
  4184. this.hiddenField = this.el.createChild(hiddenTag);
  4185. },
  4186. doLayout: function(){
  4187. if(this.rendered){
  4188. this.fromMultiselect.fs.doLayout();
  4189. this.toMultiselect.fs.doLayout();
  4190. }
  4191. },
  4192. afterRender: function(){
  4193. Ext.ux.form.ItemSelector.superclass.afterRender.call(this);
  4194. this.toStore = this.toMultiselect.store;
  4195. this.toStore.on('add', this.valueChanged, this);
  4196. this.toStore.on('remove', this.valueChanged, this);
  4197. this.toStore.on('load', this.valueChanged, this);
  4198. this.valueChanged(this.toStore);
  4199. },
  4200. toTop : function() {
  4201. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  4202. var records = [];
  4203. if (selectionsArray.length > 0) {
  4204. selectionsArray.sort();
  4205. for (var i=0; i<selectionsArray.length; i++) {
  4206. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  4207. records.push(record);
  4208. }
  4209. selectionsArray = [];
  4210. for (var i=records.length-1; i>-1; i--) {
  4211. record = records[i];
  4212. this.toMultiselect.view.store.remove(record);
  4213. this.toMultiselect.view.store.insert(0, record);
  4214. selectionsArray.push(((records.length - 1) - i));
  4215. }
  4216. }
  4217. this.toMultiselect.view.refresh();
  4218. this.toMultiselect.view.select(selectionsArray);
  4219. },
  4220. toBottom : function() {
  4221. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  4222. var records = [];
  4223. if (selectionsArray.length > 0) {
  4224. selectionsArray.sort();
  4225. for (var i=0; i<selectionsArray.length; i++) {
  4226. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  4227. records.push(record);
  4228. }
  4229. selectionsArray = [];
  4230. for (var i=0; i<records.length; i++) {
  4231. record = records[i];
  4232. this.toMultiselect.view.store.remove(record);
  4233. this.toMultiselect.view.store.add(record);
  4234. selectionsArray.push((this.toMultiselect.view.store.getCount()) - (records.length - i));
  4235. }
  4236. }
  4237. this.toMultiselect.view.refresh();
  4238. this.toMultiselect.view.select(selectionsArray);
  4239. },
  4240. up : function() {
  4241. var record = null;
  4242. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  4243. selectionsArray.sort();
  4244. var newSelectionsArray = [];
  4245. if (selectionsArray.length > 0) {
  4246. for (var i=0; i<selectionsArray.length; i++) {
  4247. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  4248. if ((selectionsArray[i] - 1) >= 0) {
  4249. this.toMultiselect.view.store.remove(record);
  4250. this.toMultiselect.view.store.insert(selectionsArray[i] - 1, record);
  4251. newSelectionsArray.push(selectionsArray[i] - 1);
  4252. }
  4253. }
  4254. this.toMultiselect.view.refresh();
  4255. this.toMultiselect.view.select(newSelectionsArray);
  4256. }
  4257. },
  4258. down : function() {
  4259. var record = null;
  4260. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  4261. selectionsArray.sort();
  4262. selectionsArray.reverse();
  4263. var newSelectionsArray = [];
  4264. if (selectionsArray.length > 0) {
  4265. for (var i=0; i<selectionsArray.length; i++) {
  4266. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  4267. if ((selectionsArray[i] + 1) < this.toMultiselect.view.store.getCount()) {
  4268. this.toMultiselect.view.store.remove(record);
  4269. this.toMultiselect.view.store.insert(selectionsArray[i] + 1, record);
  4270. newSelectionsArray.push(selectionsArray[i] + 1);
  4271. }
  4272. }
  4273. this.toMultiselect.view.refresh();
  4274. this.toMultiselect.view.select(newSelectionsArray);
  4275. }
  4276. },
  4277. fromTo : function() {
  4278. var selectionsArray = this.fromMultiselect.view.getSelectedIndexes();
  4279. var records = [];
  4280. if (selectionsArray.length > 0) {
  4281. for (var i=0; i<selectionsArray.length; i++) {
  4282. record = this.fromMultiselect.view.store.getAt(selectionsArray[i]);
  4283. records.push(record);
  4284. }
  4285. if(!this.allowDup)selectionsArray = [];
  4286. for (var i=0; i<records.length; i++) {
  4287. record = records[i];
  4288. if(this.allowDup){
  4289. var x=new Ext.data.Record();
  4290. record.id=x.id;
  4291. delete x;
  4292. this.toMultiselect.view.store.add(record);
  4293. }else{
  4294. this.fromMultiselect.view.store.remove(record);
  4295. this.toMultiselect.view.store.add(record);
  4296. selectionsArray.push((this.toMultiselect.view.store.getCount() - 1));
  4297. }
  4298. }
  4299. }
  4300. this.toMultiselect.view.refresh();
  4301. this.fromMultiselect.view.refresh();
  4302. var si = this.toMultiselect.store.sortInfo;
  4303. if(si){
  4304. this.toMultiselect.store.sort(si.field, si.direction);
  4305. }
  4306. this.toMultiselect.view.select(selectionsArray);
  4307. },
  4308. toFrom : function() {
  4309. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  4310. var records = [];
  4311. if (selectionsArray.length > 0) {
  4312. for (var i=0; i<selectionsArray.length; i++) {
  4313. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  4314. records.push(record);
  4315. }
  4316. selectionsArray = [];
  4317. for (var i=0; i<records.length; i++) {
  4318. record = records[i];
  4319. this.toMultiselect.view.store.remove(record);
  4320. if(!this.allowDup){
  4321. this.fromMultiselect.view.store.add(record);
  4322. selectionsArray.push((this.fromMultiselect.view.store.getCount() - 1));
  4323. }
  4324. }
  4325. }
  4326. this.fromMultiselect.view.refresh();
  4327. this.toMultiselect.view.refresh();
  4328. var si = this.fromMultiselect.store.sortInfo;
  4329. if (si){
  4330. this.fromMultiselect.store.sort(si.field, si.direction);
  4331. }
  4332. this.fromMultiselect.view.select(selectionsArray);
  4333. },
  4334. valueChanged: function(store) {
  4335. var record = null;
  4336. var values = [];
  4337. for (var i=0; i<store.getCount(); i++) {
  4338. record = store.getAt(i);
  4339. values.push(record.get(this.toMultiselect.valueField));
  4340. }
  4341. this.hiddenField.dom.value = values.join(this.delimiter);
  4342. this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
  4343. },
  4344. getValue : function() {
  4345. return this.hiddenField.dom.value;
  4346. },
  4347. onRowDblClick : function(vw, index, node, e) {
  4348. if (vw == this.toMultiselect.view){
  4349. this.toFrom();
  4350. } else if (vw == this.fromMultiselect.view) {
  4351. this.fromTo();
  4352. }
  4353. return this.fireEvent('rowdblclick', vw, index, node, e);
  4354. },
  4355. reset: function(){
  4356. range = this.toMultiselect.store.getRange();
  4357. this.toMultiselect.store.removeAll();
  4358. this.fromMultiselect.store.add(range);
  4359. var si = this.fromMultiselect.store.sortInfo;
  4360. if (si){
  4361. this.fromMultiselect.store.sort(si.field, si.direction);
  4362. }
  4363. this.valueChanged(this.toMultiselect.store);
  4364. }
  4365. });
  4366. Ext.reg('itemselector', Ext.ux.form.ItemSelector);
  4367. //backwards compat
  4368. Ext.ux.ItemSelector = Ext.ux.form.ItemSelector;
  4369. Ext.ns('Ext.ux.grid');
  4370. Ext.ux.grid.LockingGridView = Ext.extend(Ext.grid.GridView, {
  4371. lockText : 'Lock',
  4372. unlockText : 'Unlock',
  4373. rowBorderWidth : 1,
  4374. lockedBorderWidth : 1,
  4375. /*
  4376. * This option ensures that height between the rows is synchronized
  4377. * between the locked and unlocked sides. This option only needs to be used
  4378. * when the row heights aren't predictable.
  4379. */
  4380. syncHeights: false,
  4381. initTemplates : function(){
  4382. var ts = this.templates || {};
  4383. if (!ts.masterTpl) {
  4384. ts.masterTpl = new Ext.Template(
  4385. '<div class="x-grid3" hidefocus="true">',
  4386. '<div class="x-grid3-locked">',
  4387. '<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>',
  4388. '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{lstyle}">{lockedBody}</div><div class="x-grid3-scroll-spacer"></div></div>',
  4389. '</div>',
  4390. '<div class="x-grid3-viewport x-grid3-unlocked">',
  4391. '<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>',
  4392. '<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
  4393. '</div>',
  4394. '<div class="x-grid3-resize-marker">&#160;</div>',
  4395. '<div class="x-grid3-resize-proxy">&#160;</div>',
  4396. '</div>'
  4397. );
  4398. }
  4399. this.templates = ts;
  4400. Ext.ux.grid.LockingGridView.superclass.initTemplates.call(this);
  4401. },
  4402. getEditorParent : function(ed){
  4403. return this.el.dom;
  4404. },
  4405. initElements : function(){
  4406. var el = Ext.get(this.grid.getGridEl().dom.firstChild),
  4407. lockedWrap = el.child('div.x-grid3-locked'),
  4408. lockedHd = lockedWrap.child('div.x-grid3-header'),
  4409. lockedScroller = lockedWrap.child('div.x-grid3-scroller'),
  4410. mainWrap = el.child('div.x-grid3-viewport'),
  4411. mainHd = mainWrap.child('div.x-grid3-header'),
  4412. scroller = mainWrap.child('div.x-grid3-scroller');
  4413. if (this.grid.hideHeaders) {
  4414. lockedHd.setDisplayed(false);
  4415. mainHd.setDisplayed(false);
  4416. }
  4417. if(this.forceFit){
  4418. scroller.setStyle('overflow-x', 'hidden');
  4419. }
  4420. Ext.apply(this, {
  4421. el : el,
  4422. mainWrap: mainWrap,
  4423. mainHd : mainHd,
  4424. innerHd : mainHd.dom.firstChild,
  4425. scroller: scroller,
  4426. mainBody: scroller.child('div.x-grid3-body'),
  4427. focusEl : scroller.child('a'),
  4428. resizeMarker: el.child('div.x-grid3-resize-marker'),
  4429. resizeProxy : el.child('div.x-grid3-resize-proxy'),
  4430. lockedWrap: lockedWrap,
  4431. lockedHd: lockedHd,
  4432. lockedScroller: lockedScroller,
  4433. lockedBody: lockedScroller.child('div.x-grid3-body'),
  4434. lockedInnerHd: lockedHd.child('div.x-grid3-header-inner', true)
  4435. });
  4436. this.focusEl.swallowEvent('click', true);
  4437. },
  4438. getLockedRows : function(){
  4439. return this.hasRows() ? this.lockedBody.dom.childNodes : [];
  4440. },
  4441. getLockedRow : function(row){
  4442. return this.getLockedRows()[row];
  4443. },
  4444. getCell : function(row, col){
  4445. var lockedLen = this.cm.getLockedCount();
  4446. if(col < lockedLen){
  4447. return this.getLockedRow(row).getElementsByTagName('td')[col];
  4448. }
  4449. return Ext.ux.grid.LockingGridView.superclass.getCell.call(this, row, col - lockedLen);
  4450. },
  4451. getHeaderCell : function(index){
  4452. var lockedLen = this.cm.getLockedCount();
  4453. if(index < lockedLen){
  4454. return this.lockedHd.dom.getElementsByTagName('td')[index];
  4455. }
  4456. return Ext.ux.grid.LockingGridView.superclass.getHeaderCell.call(this, index - lockedLen);
  4457. },
  4458. addRowClass : function(row, cls){
  4459. var lockedRow = this.getLockedRow(row);
  4460. if(lockedRow){
  4461. this.fly(lockedRow).addClass(cls);
  4462. }
  4463. Ext.ux.grid.LockingGridView.superclass.addRowClass.call(this, row, cls);
  4464. },
  4465. removeRowClass : function(row, cls){
  4466. var lockedRow = this.getLockedRow(row);
  4467. if(lockedRow){
  4468. this.fly(lockedRow).removeClass(cls);
  4469. }
  4470. Ext.ux.grid.LockingGridView.superclass.removeRowClass.call(this, row, cls);
  4471. },
  4472. removeRow : function(row) {
  4473. Ext.removeNode(this.getLockedRow(row));
  4474. Ext.ux.grid.LockingGridView.superclass.removeRow.call(this, row);
  4475. },
  4476. removeRows : function(firstRow, lastRow){
  4477. var lockedBody = this.lockedBody.dom,
  4478. rowIndex = firstRow;
  4479. for(; rowIndex <= lastRow; rowIndex++){
  4480. Ext.removeNode(lockedBody.childNodes[firstRow]);
  4481. }
  4482. Ext.ux.grid.LockingGridView.superclass.removeRows.call(this, firstRow, lastRow);
  4483. },
  4484. syncScroll : function(e){
  4485. this.lockedScroller.dom.scrollTop = this.scroller.dom.scrollTop;
  4486. Ext.ux.grid.LockingGridView.superclass.syncScroll.call(this, e);
  4487. },
  4488. updateSortIcon : function(col, dir){
  4489. var sortClasses = this.sortClasses,
  4490. lockedHeaders = this.lockedHd.select('td').removeClass(sortClasses),
  4491. headers = this.mainHd.select('td').removeClass(sortClasses),
  4492. lockedLen = this.cm.getLockedCount(),
  4493. cls = sortClasses[dir == 'DESC' ? 1 : 0];
  4494. if(col < lockedLen){
  4495. lockedHeaders.item(col).addClass(cls);
  4496. }else{
  4497. headers.item(col - lockedLen).addClass(cls);
  4498. }
  4499. },
  4500. updateAllColumnWidths : function(){
  4501. var tw = this.getTotalWidth(),
  4502. clen = this.cm.getColumnCount(),
  4503. lw = this.getLockedWidth(),
  4504. llen = this.cm.getLockedCount(),
  4505. ws = [], len, i;
  4506. this.updateLockedWidth();
  4507. for(i = 0; i < clen; i++){
  4508. ws[i] = this.getColumnWidth(i);
  4509. var hd = this.getHeaderCell(i);
  4510. hd.style.width = ws[i];
  4511. }
  4512. var lns = this.getLockedRows(), ns = this.getRows(), row, trow, j;
  4513. for(i = 0, len = ns.length; i < len; i++){
  4514. row = lns[i];
  4515. row.style.width = lw;
  4516. if(row.firstChild){
  4517. row.firstChild.style.width = lw;
  4518. trow = row.firstChild.rows[0];
  4519. for (j = 0; j < llen; j++) {
  4520. trow.childNodes[j].style.width = ws[j];
  4521. }
  4522. }
  4523. row = ns[i];
  4524. row.style.width = tw;
  4525. if(row.firstChild){
  4526. row.firstChild.style.width = tw;
  4527. trow = row.firstChild.rows[0];
  4528. for (j = llen; j < clen; j++) {
  4529. trow.childNodes[j - llen].style.width = ws[j];
  4530. }
  4531. }
  4532. }
  4533. this.onAllColumnWidthsUpdated(ws, tw);
  4534. this.syncHeaderHeight();
  4535. },
  4536. updateColumnWidth : function(col, width){
  4537. var w = this.getColumnWidth(col),
  4538. llen = this.cm.getLockedCount(),
  4539. ns, rw, c, row;
  4540. this.updateLockedWidth();
  4541. if(col < llen){
  4542. ns = this.getLockedRows();
  4543. rw = this.getLockedWidth();
  4544. c = col;
  4545. }else{
  4546. ns = this.getRows();
  4547. rw = this.getTotalWidth();
  4548. c = col - llen;
  4549. }
  4550. var hd = this.getHeaderCell(col);
  4551. hd.style.width = w;
  4552. for(var i = 0, len = ns.length; i < len; i++){
  4553. row = ns[i];
  4554. row.style.width = rw;
  4555. if(row.firstChild){
  4556. row.firstChild.style.width = rw;
  4557. row.firstChild.rows[0].childNodes[c].style.width = w;
  4558. }
  4559. }
  4560. this.onColumnWidthUpdated(col, w, this.getTotalWidth());
  4561. this.syncHeaderHeight();
  4562. },
  4563. updateColumnHidden : function(col, hidden){
  4564. var llen = this.cm.getLockedCount(),
  4565. ns, rw, c, row,
  4566. display = hidden ? 'none' : '';
  4567. this.updateLockedWidth();
  4568. if(col < llen){
  4569. ns = this.getLockedRows();
  4570. rw = this.getLockedWidth();
  4571. c = col;
  4572. }else{
  4573. ns = this.getRows();
  4574. rw = this.getTotalWidth();
  4575. c = col - llen;
  4576. }
  4577. var hd = this.getHeaderCell(col);
  4578. hd.style.display = display;
  4579. for(var i = 0, len = ns.length; i < len; i++){
  4580. row = ns[i];
  4581. row.style.width = rw;
  4582. if(row.firstChild){
  4583. row.firstChild.style.width = rw;
  4584. row.firstChild.rows[0].childNodes[c].style.display = display;
  4585. }
  4586. }
  4587. this.onColumnHiddenUpdated(col, hidden, this.getTotalWidth());
  4588. delete this.lastViewWidth;
  4589. this.layout();
  4590. },
  4591. doRender : function(cs, rs, ds, startRow, colCount, stripe){
  4592. var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1,
  4593. tstyle = 'width:'+this.getTotalWidth()+';',
  4594. lstyle = 'width:'+this.getLockedWidth()+';',
  4595. buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r;
  4596. for(var j = 0, len = rs.length; j < len; j++){
  4597. r = rs[j]; cb = []; lcb = [];
  4598. var rowIndex = (j+startRow);
  4599. for(var i = 0; i < colCount; i++){
  4600. c = cs[i];
  4601. p.id = c.id;
  4602. p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
  4603. (this.cm.config[i].cellCls ? ' ' + this.cm.config[i].cellCls : '');
  4604. p.attr = p.cellAttr = '';
  4605. p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
  4606. p.style = c.style;
  4607. if(Ext.isEmpty(p.value)){
  4608. p.value = '&#160;';
  4609. }
  4610. if(this.markDirty && r.dirty && Ext.isDefined(r.modified[c.name])){
  4611. p.css += ' x-grid3-dirty-cell';
  4612. }
  4613. if(c.locked){
  4614. lcb[lcb.length] = ct.apply(p);
  4615. }else{
  4616. cb[cb.length] = ct.apply(p);
  4617. }
  4618. }
  4619. var alt = [];
  4620. if(stripe && ((rowIndex+1) % 2 === 0)){
  4621. alt[0] = 'x-grid3-row-alt';
  4622. }
  4623. if(r.dirty){
  4624. alt[1] = ' x-grid3-dirty-row';
  4625. }
  4626. rp.cols = colCount;
  4627. if(this.getRowClass){
  4628. alt[2] = this.getRowClass(r, rowIndex, rp, ds);
  4629. }
  4630. rp.alt = alt.join(' ');
  4631. rp.cells = cb.join('');
  4632. rp.tstyle = tstyle;
  4633. buf[buf.length] = rt.apply(rp);
  4634. rp.cells = lcb.join('');
  4635. rp.tstyle = lstyle;
  4636. lbuf[lbuf.length] = rt.apply(rp);
  4637. }
  4638. return [buf.join(''), lbuf.join('')];
  4639. },
  4640. processRows : function(startRow, skipStripe){
  4641. if(!this.ds || this.ds.getCount() < 1){
  4642. return;
  4643. }
  4644. var rows = this.getRows(),
  4645. lrows = this.getLockedRows(),
  4646. row, lrow;
  4647. skipStripe = skipStripe || !this.grid.stripeRows;
  4648. startRow = startRow || 0;
  4649. for(var i = 0, len = rows.length; i < len; ++i){
  4650. row = rows[i];
  4651. lrow = lrows[i];
  4652. row.rowIndex = i;
  4653. lrow.rowIndex = i;
  4654. if(!skipStripe){
  4655. row.className = row.className.replace(this.rowClsRe, ' ');
  4656. lrow.className = lrow.className.replace(this.rowClsRe, ' ');
  4657. if ((i + 1) % 2 === 0){
  4658. row.className += ' x-grid3-row-alt';
  4659. lrow.className += ' x-grid3-row-alt';
  4660. }
  4661. }
  4662. this.syncRowHeights(row, lrow);
  4663. }
  4664. if(startRow === 0){
  4665. Ext.fly(rows[0]).addClass(this.firstRowCls);
  4666. Ext.fly(lrows[0]).addClass(this.firstRowCls);
  4667. }
  4668. Ext.fly(rows[rows.length - 1]).addClass(this.lastRowCls);
  4669. Ext.fly(lrows[lrows.length - 1]).addClass(this.lastRowCls);
  4670. },
  4671. syncRowHeights: function(row1, row2){
  4672. if(this.syncHeights){
  4673. var el1 = Ext.get(row1),
  4674. el2 = Ext.get(row2),
  4675. h1 = el1.getHeight(),
  4676. h2 = el2.getHeight();
  4677. if(h1 > h2){
  4678. el2.setHeight(h1);
  4679. }else if(h2 > h1){
  4680. el1.setHeight(h2);
  4681. }
  4682. }
  4683. },
  4684. afterRender : function(){
  4685. if(!this.ds || !this.cm){
  4686. return;
  4687. }
  4688. var bd = this.renderRows() || ['&#160;', '&#160;'];
  4689. this.mainBody.dom.innerHTML = bd[0];
  4690. this.lockedBody.dom.innerHTML = bd[1];
  4691. this.processRows(0, true);
  4692. if(this.deferEmptyText !== true){
  4693. this.applyEmptyText();
  4694. }
  4695. this.grid.fireEvent('viewready', this.grid);
  4696. },
  4697. renderUI : function(){
  4698. var templates = this.templates,
  4699. header = this.renderHeaders(),
  4700. body = templates.body.apply({rows:'&#160;'});
  4701. return templates.masterTpl.apply({
  4702. body : body,
  4703. header: header[0],
  4704. ostyle: 'width:' + this.getOffsetWidth() + ';',
  4705. bstyle: 'width:' + this.getTotalWidth() + ';',
  4706. lockedBody: body,
  4707. lockedHeader: header[1],
  4708. lstyle: 'width:'+this.getLockedWidth()+';'
  4709. });
  4710. },
  4711. afterRenderUI: function(){
  4712. var g = this.grid;
  4713. this.initElements();
  4714. Ext.fly(this.innerHd).on('click', this.handleHdDown, this);
  4715. Ext.fly(this.lockedInnerHd).on('click', this.handleHdDown, this);
  4716. this.mainHd.on({
  4717. scope: this,
  4718. mouseover: this.handleHdOver,
  4719. mouseout: this.handleHdOut,
  4720. mousemove: this.handleHdMove
  4721. });
  4722. this.lockedHd.on({
  4723. scope: this,
  4724. mouseover: this.handleHdOver,
  4725. mouseout: this.handleHdOut,
  4726. mousemove: this.handleHdMove
  4727. });
  4728. this.scroller.on('scroll', this.syncScroll, this);
  4729. if(g.enableColumnResize !== false){
  4730. this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
  4731. this.splitZone.setOuterHandleElId(Ext.id(this.lockedHd.dom));
  4732. this.splitZone.setOuterHandleElId(Ext.id(this.mainHd.dom));
  4733. }
  4734. if(g.enableColumnMove){
  4735. this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
  4736. this.columnDrag.setOuterHandleElId(Ext.id(this.lockedInnerHd));
  4737. this.columnDrag.setOuterHandleElId(Ext.id(this.innerHd));
  4738. this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
  4739. }
  4740. if(g.enableHdMenu !== false){
  4741. this.hmenu = new Ext.menu.Menu({id: g.id + '-hctx'});
  4742. this.hmenu.add(
  4743. {itemId: 'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
  4744. {itemId: 'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
  4745. );
  4746. if(this.grid.enableColLock !== false){
  4747. this.hmenu.add({
  4748. itemId: 'sortSep',
  4749. xtype: 'menuseparator'
  4750. },
  4751. {itemId: 'lock', text: this.lockText, cls: 'xg-hmenu-lock'},
  4752. {itemId: 'unlock', text: this.unlockText, cls: 'xg-hmenu-unlock'}
  4753. );
  4754. }
  4755. if(g.enableColumnHide !== false){
  4756. this.colMenu = new Ext.menu.Menu({id:g.id + '-hcols-menu'});
  4757. this.colMenu.on({
  4758. scope: this,
  4759. beforeshow: this.beforeColMenuShow,
  4760. itemclick: this.handleHdMenuClick
  4761. });
  4762. this.hmenu.add('-', {
  4763. itemId:'columns',
  4764. hideOnClick: false,
  4765. text: this.columnsText,
  4766. menu: this.colMenu,
  4767. iconCls: 'x-cols-icon'
  4768. });
  4769. }
  4770. this.hmenu.on('itemclick', this.handleHdMenuClick, this);
  4771. }
  4772. if(g.trackMouseOver){
  4773. this.mainBody.on({
  4774. scope: this,
  4775. mouseover: this.onRowOver,
  4776. mouseout: this.onRowOut
  4777. });
  4778. this.lockedBody.on({
  4779. scope: this,
  4780. mouseover: this.onRowOver,
  4781. mouseout: this.onRowOut
  4782. });
  4783. }
  4784. if(g.enableDragDrop || g.enableDrag){
  4785. this.dragZone = new Ext.grid.GridDragZone(g, {
  4786. ddGroup : g.ddGroup || 'GridDD'
  4787. });
  4788. }
  4789. this.updateHeaderSortState();
  4790. },
  4791. layout : function(){
  4792. if(!this.mainBody){
  4793. return;
  4794. }
  4795. var g = this.grid;
  4796. var c = g.getGridEl();
  4797. var csize = c.getSize(true);
  4798. var vw = csize.width;
  4799. if(!g.hideHeaders && (vw < 20 || csize.height < 20)){
  4800. return;
  4801. }
  4802. this.syncHeaderHeight();
  4803. if(g.autoHeight){
  4804. this.scroller.dom.style.overflow = 'visible';
  4805. this.lockedScroller.dom.style.overflow = 'visible';
  4806. if(Ext.isWebKit){
  4807. this.scroller.dom.style.position = 'static';
  4808. this.lockedScroller.dom.style.position = 'static';
  4809. }
  4810. }else{
  4811. this.el.setSize(csize.width, csize.height);
  4812. var hdHeight = this.mainHd.getHeight();
  4813. var vh = csize.height - (hdHeight);
  4814. }
  4815. this.updateLockedWidth();
  4816. if(this.forceFit){
  4817. if(this.lastViewWidth != vw){
  4818. this.fitColumns(false, false);
  4819. this.lastViewWidth = vw;
  4820. }
  4821. }else {
  4822. this.autoExpand();
  4823. this.syncHeaderScroll();
  4824. }
  4825. this.onLayout(vw, vh);
  4826. },
  4827. getOffsetWidth : function() {
  4828. return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth() + this.getScrollOffset()) + 'px';
  4829. },
  4830. renderHeaders : function(){
  4831. var cm = this.cm,
  4832. ts = this.templates,
  4833. ct = ts.hcell,
  4834. cb = [], lcb = [],
  4835. p = {},
  4836. len = cm.getColumnCount(),
  4837. last = len - 1;
  4838. for(var i = 0; i < len; i++){
  4839. p.id = cm.getColumnId(i);
  4840. p.value = cm.getColumnHeader(i) || '';
  4841. p.style = this.getColumnStyle(i, true);
  4842. p.tooltip = this.getColumnTooltip(i);
  4843. p.css = (i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '')) +
  4844. (cm.config[i].headerCls ? ' ' + cm.config[i].headerCls : '');
  4845. if(cm.config[i].align == 'right'){
  4846. p.istyle = 'padding-right:16px';
  4847. } else {
  4848. delete p.istyle;
  4849. }
  4850. if(cm.isLocked(i)){
  4851. lcb[lcb.length] = ct.apply(p);
  4852. }else{
  4853. cb[cb.length] = ct.apply(p);
  4854. }
  4855. }
  4856. return [ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'}),
  4857. ts.header.apply({cells: lcb.join(''), tstyle:'width:'+this.getLockedWidth()+';'})];
  4858. },
  4859. updateHeaders : function(){
  4860. var hd = this.renderHeaders();
  4861. this.innerHd.firstChild.innerHTML = hd[0];
  4862. this.innerHd.firstChild.style.width = this.getOffsetWidth();
  4863. this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
  4864. this.lockedInnerHd.firstChild.innerHTML = hd[1];
  4865. var lw = this.getLockedWidth();
  4866. this.lockedInnerHd.firstChild.style.width = lw;
  4867. this.lockedInnerHd.firstChild.firstChild.style.width = lw;
  4868. },
  4869. getResolvedXY : function(resolved){
  4870. if(!resolved){
  4871. return null;
  4872. }
  4873. var c = resolved.cell, r = resolved.row;
  4874. return c ? Ext.fly(c).getXY() : [this.scroller.getX(), Ext.fly(r).getY()];
  4875. },
  4876. syncFocusEl : function(row, col, hscroll){
  4877. Ext.ux.grid.LockingGridView.superclass.syncFocusEl.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
  4878. },
  4879. ensureVisible : function(row, col, hscroll){
  4880. return Ext.ux.grid.LockingGridView.superclass.ensureVisible.call(this, row, col, col < this.cm.getLockedCount() ? false : hscroll);
  4881. },
  4882. insertRows : function(dm, firstRow, lastRow, isUpdate){
  4883. var last = dm.getCount() - 1;
  4884. if(!isUpdate && firstRow === 0 && lastRow >= last){
  4885. this.refresh();
  4886. }else{
  4887. if(!isUpdate){
  4888. this.fireEvent('beforerowsinserted', this, firstRow, lastRow);
  4889. }
  4890. var html = this.renderRows(firstRow, lastRow),
  4891. before = this.getRow(firstRow);
  4892. if(before){
  4893. if(firstRow === 0){
  4894. this.removeRowClass(0, this.firstRowCls);
  4895. }
  4896. Ext.DomHelper.insertHtml('beforeBegin', before, html[0]);
  4897. before = this.getLockedRow(firstRow);
  4898. Ext.DomHelper.insertHtml('beforeBegin', before, html[1]);
  4899. }else{
  4900. this.removeRowClass(last - 1, this.lastRowCls);
  4901. Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html[0]);
  4902. Ext.DomHelper.insertHtml('beforeEnd', this.lockedBody.dom, html[1]);
  4903. }
  4904. if(!isUpdate){
  4905. this.fireEvent('rowsinserted', this, firstRow, lastRow);
  4906. this.processRows(firstRow);
  4907. }else if(firstRow === 0 || firstRow >= last){
  4908. this.addRowClass(firstRow, firstRow === 0 ? this.firstRowCls : this.lastRowCls);
  4909. }
  4910. }
  4911. this.syncFocusEl(firstRow);
  4912. },
  4913. getColumnStyle : function(col, isHeader){
  4914. var style = !isHeader ? this.cm.config[col].cellStyle || this.cm.config[col].css || '' : this.cm.config[col].headerStyle || '';
  4915. style += 'width:'+this.getColumnWidth(col)+';';
  4916. if(this.cm.isHidden(col)){
  4917. style += 'display:none;';
  4918. }
  4919. var align = this.cm.config[col].align;
  4920. if(align){
  4921. style += 'text-align:'+align+';';
  4922. }
  4923. return style;
  4924. },
  4925. getLockedWidth : function() {
  4926. return this.cm.getTotalLockedWidth() + 'px';
  4927. },
  4928. getTotalWidth : function() {
  4929. return (this.cm.getTotalWidth() - this.cm.getTotalLockedWidth()) + 'px';
  4930. },
  4931. getColumnData : function(){
  4932. var cs = [], cm = this.cm, colCount = cm.getColumnCount();
  4933. for(var i = 0; i < colCount; i++){
  4934. var name = cm.getDataIndex(i);
  4935. cs[i] = {
  4936. name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name),
  4937. renderer : cm.getRenderer(i),
  4938. scope : cm.getRendererScope(i),
  4939. id : cm.getColumnId(i),
  4940. style : this.getColumnStyle(i),
  4941. locked : cm.isLocked(i)
  4942. };
  4943. }
  4944. return cs;
  4945. },
  4946. renderBody : function(){
  4947. var markup = this.renderRows() || ['&#160;', '&#160;'];
  4948. return [this.templates.body.apply({rows: markup[0]}), this.templates.body.apply({rows: markup[1]})];
  4949. },
  4950. refreshRow: function(record){
  4951. var store = this.ds,
  4952. colCount = this.cm.getColumnCount(),
  4953. columns = this.getColumnData(),
  4954. last = colCount - 1,
  4955. cls = ['x-grid3-row'],
  4956. rowParams = {
  4957. tstyle: String.format("width: {0};", this.getTotalWidth())
  4958. },
  4959. lockedRowParams = {
  4960. tstyle: String.format("width: {0};", this.getLockedWidth())
  4961. },
  4962. colBuffer = [],
  4963. lockedColBuffer = [],
  4964. cellTpl = this.templates.cell,
  4965. rowIndex,
  4966. row,
  4967. lockedRow,
  4968. column,
  4969. meta,
  4970. css,
  4971. i;
  4972. if (Ext.isNumber(record)) {
  4973. rowIndex = record;
  4974. record = store.getAt(rowIndex);
  4975. } else {
  4976. rowIndex = store.indexOf(record);
  4977. }
  4978. if (!record || rowIndex < 0) {
  4979. return;
  4980. }
  4981. for (i = 0; i < colCount; i++) {
  4982. column = columns[i];
  4983. if (i == 0) {
  4984. css = 'x-grid3-cell-first';
  4985. } else {
  4986. css = (i == last) ? 'x-grid3-cell-last ' : '';
  4987. }
  4988. meta = {
  4989. id: column.id,
  4990. style: column.style,
  4991. css: css,
  4992. attr: "",
  4993. cellAttr: ""
  4994. };
  4995. meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store);
  4996. if (Ext.isEmpty(meta.value)) {
  4997. meta.value = ' ';
  4998. }
  4999. if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') {
  5000. meta.css += ' x-grid3-dirty-cell';
  5001. }
  5002. if (column.locked) {
  5003. lockedColBuffer[i] = cellTpl.apply(meta);
  5004. } else {
  5005. colBuffer[i] = cellTpl.apply(meta);
  5006. }
  5007. }
  5008. row = this.getRow(rowIndex);
  5009. row.className = '';
  5010. lockedRow = this.getLockedRow(rowIndex);
  5011. lockedRow.className = '';
  5012. if (this.grid.stripeRows && ((rowIndex + 1) % 2 === 0)) {
  5013. cls.push('x-grid3-row-alt');
  5014. }
  5015. if (this.getRowClass) {
  5016. rowParams.cols = colCount;
  5017. cls.push(this.getRowClass(record, rowIndex, rowParams, store));
  5018. }
  5019. // Unlocked rows
  5020. this.fly(row).addClass(cls).setStyle(rowParams.tstyle);
  5021. rowParams.cells = colBuffer.join("");
  5022. row.innerHTML = this.templates.rowInner.apply(rowParams);
  5023. // Locked rows
  5024. this.fly(lockedRow).addClass(cls).setStyle(lockedRowParams.tstyle);
  5025. lockedRowParams.cells = lockedColBuffer.join("");
  5026. lockedRow.innerHTML = this.templates.rowInner.apply(lockedRowParams);
  5027. lockedRow.rowIndex = rowIndex;
  5028. this.syncRowHeights(row, lockedRow);
  5029. this.fireEvent('rowupdated', this, rowIndex, record);
  5030. },
  5031. refresh : function(headersToo){
  5032. this.fireEvent('beforerefresh', this);
  5033. this.grid.stopEditing(true);
  5034. var result = this.renderBody();
  5035. this.mainBody.update(result[0]).setWidth(this.getTotalWidth());
  5036. this.lockedBody.update(result[1]).setWidth(this.getLockedWidth());
  5037. if(headersToo === true){
  5038. this.updateHeaders();
  5039. this.updateHeaderSortState();
  5040. }
  5041. this.processRows(0, true);
  5042. this.layout();
  5043. this.applyEmptyText();
  5044. this.fireEvent('refresh', this);
  5045. },
  5046. onDenyColumnLock : function(){
  5047. },
  5048. initData : function(ds, cm){
  5049. if(this.cm){
  5050. this.cm.un('columnlockchange', this.onColumnLock, this);
  5051. }
  5052. Ext.ux.grid.LockingGridView.superclass.initData.call(this, ds, cm);
  5053. if(this.cm){
  5054. this.cm.on('columnlockchange', this.onColumnLock, this);
  5055. }
  5056. },
  5057. onColumnLock : function(){
  5058. this.refresh(true);
  5059. },
  5060. handleHdMenuClick : function(item){
  5061. var index = this.hdCtxIndex,
  5062. cm = this.cm,
  5063. id = item.getItemId(),
  5064. llen = cm.getLockedCount();
  5065. switch(id){
  5066. case 'lock':
  5067. if(cm.getColumnCount(true) <= llen + 1){
  5068. this.onDenyColumnLock();
  5069. return undefined;
  5070. }
  5071. cm.setLocked(index, true, llen != index);
  5072. if(llen != index){
  5073. cm.moveColumn(index, llen);
  5074. this.grid.fireEvent('columnmove', index, llen);
  5075. }
  5076. break;
  5077. case 'unlock':
  5078. if(llen - 1 != index){
  5079. cm.setLocked(index, false, true);
  5080. cm.moveColumn(index, llen - 1);
  5081. this.grid.fireEvent('columnmove', index, llen - 1);
  5082. }else{
  5083. cm.setLocked(index, false);
  5084. }
  5085. break;
  5086. default:
  5087. return Ext.ux.grid.LockingGridView.superclass.handleHdMenuClick.call(this, item);
  5088. }
  5089. return true;
  5090. },
  5091. handleHdDown : function(e, t){
  5092. Ext.ux.grid.LockingGridView.superclass.handleHdDown.call(this, e, t);
  5093. if(this.grid.enableColLock !== false){
  5094. if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
  5095. var hd = this.findHeaderCell(t),
  5096. index = this.getCellIndex(hd),
  5097. ms = this.hmenu.items, cm = this.cm;
  5098. ms.get('lock').setDisabled(cm.isLocked(index));
  5099. ms.get('unlock').setDisabled(!cm.isLocked(index));
  5100. }
  5101. }
  5102. },
  5103. syncHeaderHeight: function(){
  5104. var hrow = Ext.fly(this.innerHd).child('tr', true),
  5105. lhrow = Ext.fly(this.lockedInnerHd).child('tr', true);
  5106. hrow.style.height = 'auto';
  5107. lhrow.style.height = 'auto';
  5108. var hd = hrow.offsetHeight,
  5109. lhd = lhrow.offsetHeight,
  5110. height = Math.max(lhd, hd) + 'px';
  5111. hrow.style.height = height;
  5112. lhrow.style.height = height;
  5113. },
  5114. updateLockedWidth: function(){
  5115. var lw = this.cm.getTotalLockedWidth(),
  5116. tw = this.cm.getTotalWidth() - lw,
  5117. csize = this.grid.getGridEl().getSize(true),
  5118. lp = Ext.isBorderBox ? 0 : this.lockedBorderWidth,
  5119. rp = Ext.isBorderBox ? 0 : this.rowBorderWidth,
  5120. vw = Math.max(csize.width - lw - lp - rp, 0) + 'px',
  5121. so = this.getScrollOffset();
  5122. if(!this.grid.autoHeight){
  5123. var vh = Math.max(csize.height - this.mainHd.getHeight(), 0) + 'px';
  5124. this.lockedScroller.dom.style.height = vh;
  5125. this.scroller.dom.style.height = vh;
  5126. }
  5127. this.lockedWrap.dom.style.width = (lw + rp) + 'px';
  5128. this.scroller.dom.style.width = vw;
  5129. this.mainWrap.dom.style.left = (lw + lp + rp) + 'px';
  5130. if(this.innerHd){
  5131. this.lockedInnerHd.firstChild.style.width = lw + 'px';
  5132. this.lockedInnerHd.firstChild.firstChild.style.width = lw + 'px';
  5133. this.innerHd.style.width = vw;
  5134. this.innerHd.firstChild.style.width = (tw + rp + so) + 'px';
  5135. this.innerHd.firstChild.firstChild.style.width = tw + 'px';
  5136. }
  5137. if(this.mainBody){
  5138. this.lockedBody.dom.style.width = (lw + rp) + 'px';
  5139. this.mainBody.dom.style.width = (tw + rp) + 'px';
  5140. }
  5141. }
  5142. });
  5143. Ext.ux.grid.LockingColumnModel = Ext.extend(Ext.grid.ColumnModel, {
  5144. /**
  5145. * Returns true if the given column index is currently locked
  5146. * @param {Number} colIndex The column index
  5147. * @return {Boolean} True if the column is locked
  5148. */
  5149. isLocked : function(colIndex){
  5150. return this.config[colIndex].locked === true;
  5151. },
  5152. /**
  5153. * Locks or unlocks a given column
  5154. * @param {Number} colIndex The column index
  5155. * @param {Boolean} value True to lock, false to unlock
  5156. * @param {Boolean} suppressEvent Pass false to cause the columnlockchange event not to fire
  5157. */
  5158. setLocked : function(colIndex, value, suppressEvent){
  5159. if (this.isLocked(colIndex) == value) {
  5160. return;
  5161. }
  5162. this.config[colIndex].locked = value;
  5163. if (!suppressEvent) {
  5164. this.fireEvent('columnlockchange', this, colIndex, value);
  5165. }
  5166. },
  5167. /**
  5168. * Returns the total width of all locked columns
  5169. * @return {Number} The width of all locked columns
  5170. */
  5171. getTotalLockedWidth : function(){
  5172. var totalWidth = 0;
  5173. for (var i = 0, len = this.config.length; i < len; i++) {
  5174. if (this.isLocked(i) && !this.isHidden(i)) {
  5175. totalWidth += this.getColumnWidth(i);
  5176. }
  5177. }
  5178. return totalWidth;
  5179. },
  5180. /**
  5181. * Returns the total number of locked columns
  5182. * @return {Number} The number of locked columns
  5183. */
  5184. getLockedCount : function() {
  5185. var len = this.config.length;
  5186. for (var i = 0; i < len; i++) {
  5187. if (!this.isLocked(i)) {
  5188. return i;
  5189. }
  5190. }
  5191. //if we get to this point all of the columns are locked so we return the total
  5192. return len;
  5193. },
  5194. /**
  5195. * Moves a column from one position to another
  5196. * @param {Number} oldIndex The current column index
  5197. * @param {Number} newIndex The destination column index
  5198. */
  5199. moveColumn : function(oldIndex, newIndex){
  5200. var oldLocked = this.isLocked(oldIndex),
  5201. newLocked = this.isLocked(newIndex);
  5202. if (oldIndex < newIndex && oldLocked && !newLocked) {
  5203. this.setLocked(oldIndex, false, true);
  5204. } else if (oldIndex > newIndex && !oldLocked && newLocked) {
  5205. this.setLocked(oldIndex, true, true);
  5206. }
  5207. Ext.ux.grid.LockingColumnModel.superclass.moveColumn.apply(this, arguments);
  5208. }
  5209. });
  5210. Ext.ns('Ext.ux.form');
  5211. /**
  5212. * @class Ext.ux.form.MultiSelect
  5213. * @extends Ext.form.Field
  5214. * A control that allows selection and form submission of multiple list items.
  5215. *
  5216. * @history
  5217. * 2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
  5218. * 2008-06-19 bpm Docs and demo code clean up
  5219. *
  5220. * @constructor
  5221. * Create a new MultiSelect
  5222. * @param {Object} config Configuration options
  5223. * @xtype multiselect
  5224. */
  5225. Ext.ux.form.MultiSelect = Ext.extend(Ext.form.Field, {
  5226. /**
  5227. * @cfg {String} legend Wraps the object with a fieldset and specified legend.
  5228. */
  5229. /**
  5230. * @cfg {Ext.ListView} view The {@link Ext.ListView} used to render the multiselect list.
  5231. */
  5232. /**
  5233. * @cfg {String/Array} dragGroup The ddgroup name(s) for the MultiSelect DragZone (defaults to undefined).
  5234. */
  5235. /**
  5236. * @cfg {String/Array} dropGroup The ddgroup name(s) for the MultiSelect DropZone (defaults to undefined).
  5237. */
  5238. /**
  5239. * @cfg {Boolean} ddReorder Whether the items in the MultiSelect list are drag/drop reorderable (defaults to false).
  5240. */
  5241. ddReorder:false,
  5242. /**
  5243. * @cfg {Object/Array} tbar The top toolbar of the control. This can be a {@link Ext.Toolbar} object, a
  5244. * toolbar config, or an array of buttons/button configs to be added to the toolbar.
  5245. */
  5246. /**
  5247. * @cfg {String} appendOnly True if the list should only allow append drops when drag/drop is enabled
  5248. * (use for lists which are sorted, defaults to false).
  5249. */
  5250. appendOnly:false,
  5251. /**
  5252. * @cfg {Number} width Width in pixels of the control (defaults to 100).
  5253. */
  5254. width:100,
  5255. /**
  5256. * @cfg {Number} height Height in pixels of the control (defaults to 100).
  5257. */
  5258. height:100,
  5259. /**
  5260. * @cfg {String/Number} displayField Name/Index of the desired display field in the dataset (defaults to 0).
  5261. */
  5262. displayField:0,
  5263. /**
  5264. * @cfg {String/Number} valueField Name/Index of the desired value field in the dataset (defaults to 1).
  5265. */
  5266. valueField:1,
  5267. /**
  5268. * @cfg {Boolean} allowBlank False to require at least one item in the list to be selected, true to allow no
  5269. * selection (defaults to true).
  5270. */
  5271. allowBlank:true,
  5272. /**
  5273. * @cfg {Number} minSelections Minimum number of selections allowed (defaults to 0).
  5274. */
  5275. minSelections:0,
  5276. /**
  5277. * @cfg {Number} maxSelections Maximum number of selections allowed (defaults to Number.MAX_VALUE).
  5278. */
  5279. maxSelections:Number.MAX_VALUE,
  5280. /**
  5281. * @cfg {String} blankText Default text displayed when the control contains no items (defaults to the same value as
  5282. * {@link Ext.form.TextField#blankText}.
  5283. */
  5284. blankText:Ext.form.TextField.prototype.blankText,
  5285. /**
  5286. * @cfg {String} minSelectionsText Validation message displayed when {@link #minSelections} is not met (defaults to 'Minimum {0}
  5287. * item(s) required'). The {0} token will be replaced by the value of {@link #minSelections}.
  5288. */
  5289. minSelectionsText:'Minimum {0} item(s) required',
  5290. /**
  5291. * @cfg {String} maxSelectionsText Validation message displayed when {@link #maxSelections} is not met (defaults to 'Maximum {0}
  5292. * item(s) allowed'). The {0} token will be replaced by the value of {@link #maxSelections}.
  5293. */
  5294. maxSelectionsText:'Maximum {0} item(s) allowed',
  5295. /**
  5296. * @cfg {String} delimiter The string used to delimit between items when set or returned as a string of values
  5297. * (defaults to ',').
  5298. */
  5299. delimiter:',',
  5300. /**
  5301. * @cfg {Ext.data.Store/Array} store The data source to which this MultiSelect is bound (defaults to <tt>undefined</tt>).
  5302. * Acceptable values for this property are:
  5303. * <div class="mdetail-params"><ul>
  5304. * <li><b>any {@link Ext.data.Store Store} subclass</b></li>
  5305. * <li><b>an Array</b> : Arrays will be converted to a {@link Ext.data.ArrayStore} internally.
  5306. * <div class="mdetail-params"><ul>
  5307. * <li><b>1-dimensional array</b> : (e.g., <tt>['Foo','Bar']</tt>)<div class="sub-desc">
  5308. * A 1-dimensional array will automatically be expanded (each array item will be the combo
  5309. * {@link #valueField value} and {@link #displayField text})</div></li>
  5310. * <li><b>2-dimensional array</b> : (e.g., <tt>[['f','Foo'],['b','Bar']]</tt>)<div class="sub-desc">
  5311. * For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo
  5312. * {@link #valueField value}, while the value at index 1 is assumed to be the combo {@link #displayField text}.
  5313. * </div></li></ul></div></li></ul></div>
  5314. */
  5315. cls: 'ux-form-multiselect',
  5316. // private
  5317. defaultAutoCreate : {tag: "div"},
  5318. // private
  5319. initComponent: function(){
  5320. Ext.ux.form.MultiSelect.superclass.initComponent.call(this);
  5321. if(Ext.isArray(this.store)){
  5322. if (Ext.isArray(this.store[0])){
  5323. this.store = new Ext.data.ArrayStore({
  5324. fields: ['value','text'],
  5325. data: this.store
  5326. });
  5327. this.valueField = 'value';
  5328. }else{
  5329. this.store = new Ext.data.ArrayStore({
  5330. fields: ['text'],
  5331. data: this.store,
  5332. expandData: true
  5333. });
  5334. this.valueField = 'text';
  5335. }
  5336. this.displayField = 'text';
  5337. } else {
  5338. this.store = Ext.StoreMgr.lookup(this.store);
  5339. }
  5340. this.addEvents({
  5341. 'dblclick' : true,
  5342. 'click' : true,
  5343. 'change' : true,
  5344. 'drop' : true
  5345. });
  5346. },
  5347. // private
  5348. onRender: function(ct, position){
  5349. Ext.ux.form.MultiSelect.superclass.onRender.call(this, ct, position);
  5350. var fs = this.fs = new Ext.form.FieldSet({
  5351. renderTo: this.el,
  5352. title: this.legend,
  5353. height: this.height,
  5354. width: this.width,
  5355. style: "padding:0;",
  5356. tbar: this.tbar
  5357. });
  5358. fs.body.addClass('ux-mselect');
  5359. this.view = new Ext.ListView({
  5360. selectedClass: 'ux-mselect-selected',
  5361. multiSelect: true,
  5362. store: this.store,
  5363. columns: [{ header: 'Value', width: 1, dataIndex: this.displayField }],
  5364. hideHeaders: true
  5365. });
  5366. fs.add(this.view);
  5367. this.view.on('click', this.onViewClick, this);
  5368. this.view.on('beforeclick', this.onViewBeforeClick, this);
  5369. this.view.on('dblclick', this.onViewDblClick, this);
  5370. this.hiddenName = this.name || Ext.id();
  5371. var hiddenTag = { tag: "input", type: "hidden", value: "", name: this.hiddenName };
  5372. this.hiddenField = this.el.createChild(hiddenTag);
  5373. this.hiddenField.dom.disabled = this.hiddenName != this.name;
  5374. fs.doLayout();
  5375. },
  5376. // private
  5377. afterRender: function(){
  5378. Ext.ux.form.MultiSelect.superclass.afterRender.call(this);
  5379. if (this.ddReorder && !this.dragGroup && !this.dropGroup){
  5380. this.dragGroup = this.dropGroup = 'MultiselectDD-' + Ext.id();
  5381. }
  5382. if (this.draggable || this.dragGroup){
  5383. this.dragZone = new Ext.ux.form.MultiSelect.DragZone(this, {
  5384. ddGroup: this.dragGroup
  5385. });
  5386. }
  5387. if (this.droppable || this.dropGroup){
  5388. this.dropZone = new Ext.ux.form.MultiSelect.DropZone(this, {
  5389. ddGroup: this.dropGroup
  5390. });
  5391. }
  5392. },
  5393. // private
  5394. onViewClick: function(vw, index, node, e) {
  5395. this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
  5396. this.hiddenField.dom.value = this.getValue();
  5397. this.fireEvent('click', this, e);
  5398. this.validate();
  5399. },
  5400. // private
  5401. onViewBeforeClick: function(vw, index, node, e) {
  5402. if (this.disabled || this.readOnly) {
  5403. return false;
  5404. }
  5405. },
  5406. // private
  5407. onViewDblClick : function(vw, index, node, e) {
  5408. return this.fireEvent('dblclick', vw, index, node, e);
  5409. },
  5410. /**
  5411. * Returns an array of data values for the selected items in the list. The values will be separated
  5412. * by {@link #delimiter}.
  5413. * @return {Array} value An array of string data values
  5414. */
  5415. getValue: function(valueField){
  5416. var returnArray = [];
  5417. var selectionsArray = this.view.getSelectedIndexes();
  5418. if (selectionsArray.length == 0) {return '';}
  5419. for (var i=0; i<selectionsArray.length; i++) {
  5420. returnArray.push(this.store.getAt(selectionsArray[i]).get((valueField != null) ? valueField : this.valueField));
  5421. }
  5422. return returnArray.join(this.delimiter);
  5423. },
  5424. /**
  5425. * Sets a delimited string (using {@link #delimiter}) or array of data values into the list.
  5426. * @param {String/Array} values The values to set
  5427. */
  5428. setValue: function(values) {
  5429. var index;
  5430. var selections = [];
  5431. this.view.clearSelections();
  5432. this.hiddenField.dom.value = '';
  5433. if (!values || (values == '')) { return; }
  5434. if (!Ext.isArray(values)) { values = values.split(this.delimiter); }
  5435. for (var i=0; i<values.length; i++) {
  5436. index = this.view.store.indexOf(this.view.store.query(this.valueField,
  5437. new RegExp('^' + values[i] + '$', "i")).itemAt(0));
  5438. selections.push(index);
  5439. }
  5440. this.view.select(selections);
  5441. this.hiddenField.dom.value = this.getValue();
  5442. this.validate();
  5443. },
  5444. // inherit docs
  5445. reset : function() {
  5446. this.setValue('');
  5447. },
  5448. // inherit docs
  5449. getRawValue: function(valueField) {
  5450. var tmp = this.getValue(valueField);
  5451. if (tmp.length) {
  5452. tmp = tmp.split(this.delimiter);
  5453. }
  5454. else {
  5455. tmp = [];
  5456. }
  5457. return tmp;
  5458. },
  5459. // inherit docs
  5460. setRawValue: function(values){
  5461. setValue(values);
  5462. },
  5463. // inherit docs
  5464. validateValue : function(value){
  5465. if (value.length < 1) { // if it has no value
  5466. if (this.allowBlank) {
  5467. this.clearInvalid();
  5468. return true;
  5469. } else {
  5470. this.markInvalid(this.blankText);
  5471. return false;
  5472. }
  5473. }
  5474. if (value.length < this.minSelections) {
  5475. this.markInvalid(String.format(this.minSelectionsText, this.minSelections));
  5476. return false;
  5477. }
  5478. if (value.length > this.maxSelections) {
  5479. this.markInvalid(String.format(this.maxSelectionsText, this.maxSelections));
  5480. return false;
  5481. }
  5482. return true;
  5483. },
  5484. // inherit docs
  5485. disable: function(){
  5486. this.disabled = true;
  5487. this.hiddenField.dom.disabled = true;
  5488. this.fs.disable();
  5489. },
  5490. // inherit docs
  5491. enable: function(){
  5492. this.disabled = false;
  5493. this.hiddenField.dom.disabled = false;
  5494. this.fs.enable();
  5495. },
  5496. // inherit docs
  5497. destroy: function(){
  5498. Ext.destroy(this.fs, this.dragZone, this.dropZone);
  5499. Ext.ux.form.MultiSelect.superclass.destroy.call(this);
  5500. }
  5501. });
  5502. Ext.reg('multiselect', Ext.ux.form.MultiSelect);
  5503. //backwards compat
  5504. Ext.ux.Multiselect = Ext.ux.form.MultiSelect;
  5505. Ext.ux.form.MultiSelect.DragZone = function(ms, config){
  5506. this.ms = ms;
  5507. this.view = ms.view;
  5508. var ddGroup = config.ddGroup || 'MultiselectDD';
  5509. var dd;
  5510. if (Ext.isArray(ddGroup)){
  5511. dd = ddGroup.shift();
  5512. } else {
  5513. dd = ddGroup;
  5514. ddGroup = null;
  5515. }
  5516. Ext.ux.form.MultiSelect.DragZone.superclass.constructor.call(this, this.ms.fs.body, { containerScroll: true, ddGroup: dd });
  5517. this.setDraggable(ddGroup);
  5518. };
  5519. Ext.extend(Ext.ux.form.MultiSelect.DragZone, Ext.dd.DragZone, {
  5520. onInitDrag : function(x, y){
  5521. var el = Ext.get(this.dragData.ddel.cloneNode(true));
  5522. this.proxy.update(el.dom);
  5523. el.setWidth(el.child('em').getWidth());
  5524. this.onStartDrag(x, y);
  5525. return true;
  5526. },
  5527. // private
  5528. collectSelection: function(data) {
  5529. data.repairXY = Ext.fly(this.view.getSelectedNodes()[0]).getXY();
  5530. var i = 0;
  5531. this.view.store.each(function(rec){
  5532. if (this.view.isSelected(i)) {
  5533. var n = this.view.getNode(i);
  5534. var dragNode = n.cloneNode(true);
  5535. dragNode.id = Ext.id();
  5536. data.ddel.appendChild(dragNode);
  5537. data.records.push(this.view.store.getAt(i));
  5538. data.viewNodes.push(n);
  5539. }
  5540. i++;
  5541. }, this);
  5542. },
  5543. // override
  5544. onEndDrag: function(data, e) {
  5545. var d = Ext.get(this.dragData.ddel);
  5546. if (d && d.hasClass("multi-proxy")) {
  5547. d.remove();
  5548. }
  5549. },
  5550. // override
  5551. getDragData: function(e){
  5552. var target = this.view.findItemFromChild(e.getTarget());
  5553. if(target) {
  5554. if (!this.view.isSelected(target) && !e.ctrlKey && !e.shiftKey) {
  5555. this.view.select(target);
  5556. this.ms.setValue(this.ms.getValue());
  5557. }
  5558. if (this.view.getSelectionCount() == 0 || e.ctrlKey || e.shiftKey) return false;
  5559. var dragData = {
  5560. sourceView: this.view,
  5561. viewNodes: [],
  5562. records: []
  5563. };
  5564. if (this.view.getSelectionCount() == 1) {
  5565. var i = this.view.getSelectedIndexes()[0];
  5566. var n = this.view.getNode(i);
  5567. dragData.viewNodes.push(dragData.ddel = n);
  5568. dragData.records.push(this.view.store.getAt(i));
  5569. dragData.repairXY = Ext.fly(n).getXY();
  5570. } else {
  5571. dragData.ddel = document.createElement('div');
  5572. dragData.ddel.className = 'multi-proxy';
  5573. this.collectSelection(dragData);
  5574. }
  5575. return dragData;
  5576. }
  5577. return false;
  5578. },
  5579. // override the default repairXY.
  5580. getRepairXY : function(e){
  5581. return this.dragData.repairXY;
  5582. },
  5583. // private
  5584. setDraggable: function(ddGroup){
  5585. if (!ddGroup) return;
  5586. if (Ext.isArray(ddGroup)) {
  5587. Ext.each(ddGroup, this.setDraggable, this);
  5588. return;
  5589. }
  5590. this.addToGroup(ddGroup);
  5591. }
  5592. });
  5593. Ext.ux.form.MultiSelect.DropZone = function(ms, config){
  5594. this.ms = ms;
  5595. this.view = ms.view;
  5596. var ddGroup = config.ddGroup || 'MultiselectDD';
  5597. var dd;
  5598. if (Ext.isArray(ddGroup)){
  5599. dd = ddGroup.shift();
  5600. } else {
  5601. dd = ddGroup;
  5602. ddGroup = null;
  5603. }
  5604. Ext.ux.form.MultiSelect.DropZone.superclass.constructor.call(this, this.ms.fs.body, { containerScroll: true, ddGroup: dd });
  5605. this.setDroppable(ddGroup);
  5606. };
  5607. Ext.extend(Ext.ux.form.MultiSelect.DropZone, Ext.dd.DropZone, {
  5608. /**
  5609. * Part of the Ext.dd.DropZone interface. If no target node is found, the
  5610. * whole Element becomes the target, and this causes the drop gesture to append.
  5611. */
  5612. getTargetFromEvent : function(e) {
  5613. var target = e.getTarget();
  5614. return target;
  5615. },
  5616. // private
  5617. getDropPoint : function(e, n, dd){
  5618. if (n == this.ms.fs.body.dom) { return "below"; }
  5619. var t = Ext.lib.Dom.getY(n), b = t + n.offsetHeight;
  5620. var c = t + (b - t) / 2;
  5621. var y = Ext.lib.Event.getPageY(e);
  5622. if(y <= c) {
  5623. return "above";
  5624. }else{
  5625. return "below";
  5626. }
  5627. },
  5628. // private
  5629. isValidDropPoint: function(pt, n, data) {
  5630. if (!data.viewNodes || (data.viewNodes.length != 1)) {
  5631. return true;
  5632. }
  5633. var d = data.viewNodes[0];
  5634. if (d == n) {
  5635. return false;
  5636. }
  5637. if ((pt == "below") && (n.nextSibling == d)) {
  5638. return false;
  5639. }
  5640. if ((pt == "above") && (n.previousSibling == d)) {
  5641. return false;
  5642. }
  5643. return true;
  5644. },
  5645. // override
  5646. onNodeEnter : function(n, dd, e, data){
  5647. return false;
  5648. },
  5649. // override
  5650. onNodeOver : function(n, dd, e, data){
  5651. var dragElClass = this.dropNotAllowed;
  5652. var pt = this.getDropPoint(e, n, dd);
  5653. if (this.isValidDropPoint(pt, n, data)) {
  5654. if (this.ms.appendOnly) {
  5655. return "x-tree-drop-ok-below";
  5656. }
  5657. // set the insert point style on the target node
  5658. if (pt) {
  5659. var targetElClass;
  5660. if (pt == "above"){
  5661. dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
  5662. targetElClass = "x-view-drag-insert-above";
  5663. } else {
  5664. dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
  5665. targetElClass = "x-view-drag-insert-below";
  5666. }
  5667. if (this.lastInsertClass != targetElClass){
  5668. Ext.fly(n).replaceClass(this.lastInsertClass, targetElClass);
  5669. this.lastInsertClass = targetElClass;
  5670. }
  5671. }
  5672. }
  5673. return dragElClass;
  5674. },
  5675. // private
  5676. onNodeOut : function(n, dd, e, data){
  5677. this.removeDropIndicators(n);
  5678. },
  5679. // private
  5680. onNodeDrop : function(n, dd, e, data){
  5681. if (this.ms.fireEvent("drop", this, n, dd, e, data) === false) {
  5682. return false;
  5683. }
  5684. var pt = this.getDropPoint(e, n, dd);
  5685. if (n != this.ms.fs.body.dom)
  5686. n = this.view.findItemFromChild(n);
  5687. if(this.ms.appendOnly) {
  5688. insertAt = this.view.store.getCount();
  5689. } else {
  5690. insertAt = n == this.ms.fs.body.dom ? this.view.store.getCount() - 1 : this.view.indexOf(n);
  5691. if (pt == "below") {
  5692. insertAt++;
  5693. }
  5694. }
  5695. var dir = false;
  5696. // Validate if dragging within the same MultiSelect
  5697. if (data.sourceView == this.view) {
  5698. // If the first element to be inserted below is the target node, remove it
  5699. if (pt == "below") {
  5700. if (data.viewNodes[0] == n) {
  5701. data.viewNodes.shift();
  5702. }
  5703. } else { // If the last element to be inserted above is the target node, remove it
  5704. if (data.viewNodes[data.viewNodes.length - 1] == n) {
  5705. data.viewNodes.pop();
  5706. }
  5707. }
  5708. // Nothing to drop...
  5709. if (!data.viewNodes.length) {
  5710. return false;
  5711. }
  5712. // If we are moving DOWN, then because a store.remove() takes place first,
  5713. // the insertAt must be decremented.
  5714. if (insertAt > this.view.store.indexOf(data.records[0])) {
  5715. dir = 'down';
  5716. insertAt--;
  5717. }
  5718. }
  5719. for (var i = 0; i < data.records.length; i++) {
  5720. var r = data.records[i];
  5721. if (data.sourceView) {
  5722. data.sourceView.store.remove(r);
  5723. }
  5724. this.view.store.insert(dir == 'down' ? insertAt : insertAt++, r);
  5725. var si = this.view.store.sortInfo;
  5726. if(si){
  5727. this.view.store.sort(si.field, si.direction);
  5728. }
  5729. }
  5730. return true;
  5731. },
  5732. // private
  5733. removeDropIndicators : function(n){
  5734. if(n){
  5735. Ext.fly(n).removeClass([
  5736. "x-view-drag-insert-above",
  5737. "x-view-drag-insert-left",
  5738. "x-view-drag-insert-right",
  5739. "x-view-drag-insert-below"]);
  5740. this.lastInsertClass = "_noclass";
  5741. }
  5742. },
  5743. // private
  5744. setDroppable: function(ddGroup){
  5745. if (!ddGroup) return;
  5746. if (Ext.isArray(ddGroup)) {
  5747. Ext.each(ddGroup, this.setDroppable, this);
  5748. return;
  5749. }
  5750. this.addToGroup(ddGroup);
  5751. }
  5752. });
  5753. /* Fix for Opera, which does not seem to include the map function on Array's */
  5754. if (!Array.prototype.map) {
  5755. Array.prototype.map = function(fun){
  5756. var len = this.length;
  5757. if (typeof fun != 'function') {
  5758. throw new TypeError();
  5759. }
  5760. var res = new Array(len);
  5761. var thisp = arguments[1];
  5762. for (var i = 0; i < len; i++) {
  5763. if (i in this) {
  5764. res[i] = fun.call(thisp, this[i], i, this);
  5765. }
  5766. }
  5767. return res;
  5768. };
  5769. }
  5770. Ext.ns('Ext.ux.data');
  5771. /**
  5772. * @class Ext.ux.data.PagingMemoryProxy
  5773. * @extends Ext.data.MemoryProxy
  5774. * <p>Paging Memory Proxy, allows to use paging grid with in memory dataset</p>
  5775. */
  5776. Ext.ux.data.PagingMemoryProxy = Ext.extend(Ext.data.MemoryProxy, {
  5777. constructor : function(data){
  5778. Ext.ux.data.PagingMemoryProxy.superclass.constructor.call(this);
  5779. this.data = data;
  5780. },
  5781. doRequest : function(action, rs, params, reader, callback, scope, options){
  5782. params = params ||
  5783. {};
  5784. var result;
  5785. try {
  5786. result = reader.readRecords(this.data);
  5787. }
  5788. catch (e) {
  5789. this.fireEvent('loadexception', this, options, null, e);
  5790. callback.call(scope, null, options, false);
  5791. return;
  5792. }
  5793. // filtering
  5794. if (params.filter !== undefined) {
  5795. result.records = result.records.filter(function(el){
  5796. if (typeof(el) == 'object') {
  5797. var att = params.filterCol || 0;
  5798. return String(el.data[att]).match(params.filter) ? true : false;
  5799. }
  5800. else {
  5801. return String(el).match(params.filter) ? true : false;
  5802. }
  5803. });
  5804. result.totalRecords = result.records.length;
  5805. }
  5806. // sorting
  5807. if (params.sort !== undefined) {
  5808. // use integer as params.sort to specify column, since arrays are not named
  5809. // params.sort=0; would also match a array without columns
  5810. var dir = String(params.dir).toUpperCase() == 'DESC' ? -1 : 1;
  5811. var fn = function(v1, v2){
  5812. return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
  5813. };
  5814. result.records.sort(function(a, b){
  5815. var v = 0;
  5816. if (typeof(a) == 'object') {
  5817. v = fn(a.data[params.sort], b.data[params.sort]) * dir;
  5818. }
  5819. else {
  5820. v = fn(a, b) * dir;
  5821. }
  5822. if (v == 0) {
  5823. v = (a.index < b.index ? -1 : 1);
  5824. }
  5825. return v;
  5826. });
  5827. }
  5828. // paging (use undefined cause start can also be 0 (thus false))
  5829. if (params.start !== undefined && params.limit !== undefined) {
  5830. result.records = result.records.slice(params.start, params.start + params.limit);
  5831. }
  5832. callback.call(scope, result, options, true);
  5833. }
  5834. });
  5835. //backwards compat.
  5836. Ext.data.PagingMemoryProxy = Ext.ux.data.PagingMemoryProxy;
  5837. Ext.ux.PanelResizer = Ext.extend(Ext.util.Observable, {
  5838. minHeight: 0,
  5839. maxHeight:10000000,
  5840. constructor: function(config){
  5841. Ext.apply(this, config);
  5842. this.events = {};
  5843. Ext.ux.PanelResizer.superclass.constructor.call(this, config);
  5844. },
  5845. init : function(p){
  5846. this.panel = p;
  5847. if(this.panel.elements.indexOf('footer')==-1){
  5848. p.elements += ',footer';
  5849. }
  5850. p.on('render', this.onRender, this);
  5851. },
  5852. onRender : function(p){
  5853. this.handle = p.footer.createChild({cls:'x-panel-resize'});
  5854. this.tracker = new Ext.dd.DragTracker({
  5855. onStart: this.onDragStart.createDelegate(this),
  5856. onDrag: this.onDrag.createDelegate(this),
  5857. onEnd: this.onDragEnd.createDelegate(this),
  5858. tolerance: 3,
  5859. autoStart: 300
  5860. });
  5861. this.tracker.initEl(this.handle);
  5862. p.on('beforedestroy', this.tracker.destroy, this.tracker);
  5863. },
  5864. // private
  5865. onDragStart: function(e){
  5866. this.dragging = true;
  5867. this.startHeight = this.panel.el.getHeight();
  5868. this.fireEvent('dragstart', this, e);
  5869. },
  5870. // private
  5871. onDrag: function(e){
  5872. this.panel.setHeight((this.startHeight-this.tracker.getOffset()[1]).constrain(this.minHeight, this.maxHeight));
  5873. this.fireEvent('drag', this, e);
  5874. },
  5875. // private
  5876. onDragEnd: function(e){
  5877. this.dragging = false;
  5878. this.fireEvent('dragend', this, e);
  5879. }
  5880. });
  5881. Ext.preg('panelresizer', Ext.ux.PanelResizer);Ext.ux.Portal = Ext.extend(Ext.Panel, {
  5882. layout : 'column',
  5883. autoScroll : true,
  5884. cls : 'x-portal',
  5885. defaultType : 'portalcolumn',
  5886. initComponent : function(){
  5887. Ext.ux.Portal.superclass.initComponent.call(this);
  5888. this.addEvents({
  5889. validatedrop:true,
  5890. beforedragover:true,
  5891. dragover:true,
  5892. beforedrop:true,
  5893. drop:true
  5894. });
  5895. },
  5896. initEvents : function(){
  5897. Ext.ux.Portal.superclass.initEvents.call(this);
  5898. this.dd = new Ext.ux.Portal.DropZone(this, this.dropConfig);
  5899. },
  5900. beforeDestroy : function() {
  5901. if(this.dd){
  5902. this.dd.unreg();
  5903. }
  5904. Ext.ux.Portal.superclass.beforeDestroy.call(this);
  5905. }
  5906. });
  5907. Ext.reg('portal', Ext.ux.Portal);
  5908. Ext.ux.Portal.DropZone = Ext.extend(Ext.dd.DropTarget, {
  5909. constructor : function(portal, cfg){
  5910. this.portal = portal;
  5911. Ext.dd.ScrollManager.register(portal.body);
  5912. Ext.ux.Portal.DropZone.superclass.constructor.call(this, portal.bwrap.dom, cfg);
  5913. portal.body.ddScrollConfig = this.ddScrollConfig;
  5914. },
  5915. ddScrollConfig : {
  5916. vthresh: 50,
  5917. hthresh: -1,
  5918. animate: true,
  5919. increment: 200
  5920. },
  5921. createEvent : function(dd, e, data, col, c, pos){
  5922. return {
  5923. portal: this.portal,
  5924. panel: data.panel,
  5925. columnIndex: col,
  5926. column: c,
  5927. position: pos,
  5928. data: data,
  5929. source: dd,
  5930. rawEvent: e,
  5931. status: this.dropAllowed
  5932. };
  5933. },
  5934. notifyOver : function(dd, e, data){
  5935. var xy = e.getXY(), portal = this.portal, px = dd.proxy;
  5936. // case column widths
  5937. if(!this.grid){
  5938. this.grid = this.getGrid();
  5939. }
  5940. // handle case scroll where scrollbars appear during drag
  5941. var cw = portal.body.dom.clientWidth;
  5942. if(!this.lastCW){
  5943. this.lastCW = cw;
  5944. }else if(this.lastCW != cw){
  5945. this.lastCW = cw;
  5946. portal.doLayout();
  5947. this.grid = this.getGrid();
  5948. }
  5949. // determine column
  5950. var col = 0, xs = this.grid.columnX, cmatch = false;
  5951. for(var len = xs.length; col < len; col++){
  5952. if(xy[0] < (xs[col].x + xs[col].w)){
  5953. cmatch = true;
  5954. break;
  5955. }
  5956. }
  5957. // no match, fix last index
  5958. if(!cmatch){
  5959. col--;
  5960. }
  5961. // find insert position
  5962. var p, match = false, pos = 0,
  5963. c = portal.items.itemAt(col),
  5964. items = c.items.items, overSelf = false;
  5965. for(var len = items.length; pos < len; pos++){
  5966. p = items[pos];
  5967. var h = p.el.getHeight();
  5968. if(h === 0){
  5969. overSelf = true;
  5970. }
  5971. else if((p.el.getY()+(h/2)) > xy[1]){
  5972. match = true;
  5973. break;
  5974. }
  5975. }
  5976. pos = (match && p ? pos : c.items.getCount()) + (overSelf ? -1 : 0);
  5977. var overEvent = this.createEvent(dd, e, data, col, c, pos);
  5978. if(portal.fireEvent('validatedrop', overEvent) !== false &&
  5979. portal.fireEvent('beforedragover', overEvent) !== false){
  5980. // make sure proxy width is fluid
  5981. px.getProxy().setWidth('auto');
  5982. if(p){
  5983. px.moveProxy(p.el.dom.parentNode, match ? p.el.dom : null);
  5984. }else{
  5985. px.moveProxy(c.el.dom, null);
  5986. }
  5987. this.lastPos = {c: c, col: col, p: overSelf || (match && p) ? pos : false};
  5988. this.scrollPos = portal.body.getScroll();
  5989. portal.fireEvent('dragover', overEvent);
  5990. return overEvent.status;
  5991. }else{
  5992. return overEvent.status;
  5993. }
  5994. },
  5995. notifyOut : function(){
  5996. delete this.grid;
  5997. },
  5998. notifyDrop : function(dd, e, data){
  5999. delete this.grid;
  6000. if(!this.lastPos){
  6001. return;
  6002. }
  6003. var c = this.lastPos.c,
  6004. col = this.lastPos.col,
  6005. pos = this.lastPos.p,
  6006. panel = dd.panel,
  6007. dropEvent = this.createEvent(dd, e, data, col, c,
  6008. pos !== false ? pos : c.items.getCount());
  6009. if(this.portal.fireEvent('validatedrop', dropEvent) !== false &&
  6010. this.portal.fireEvent('beforedrop', dropEvent) !== false){
  6011. dd.proxy.getProxy().remove();
  6012. panel.el.dom.parentNode.removeChild(dd.panel.el.dom);
  6013. if(pos !== false){
  6014. c.insert(pos, panel);
  6015. }else{
  6016. c.add(panel);
  6017. }
  6018. c.doLayout();
  6019. this.portal.fireEvent('drop', dropEvent);
  6020. // scroll position is lost on drop, fix it
  6021. var st = this.scrollPos.top;
  6022. if(st){
  6023. var d = this.portal.body.dom;
  6024. setTimeout(function(){
  6025. d.scrollTop = st;
  6026. }, 10);
  6027. }
  6028. }
  6029. delete this.lastPos;
  6030. },
  6031. // internal cache of body and column coords
  6032. getGrid : function(){
  6033. var box = this.portal.bwrap.getBox();
  6034. box.columnX = [];
  6035. this.portal.items.each(function(c){
  6036. box.columnX.push({x: c.el.getX(), w: c.el.getWidth()});
  6037. });
  6038. return box;
  6039. },
  6040. // unregister the dropzone from ScrollManager
  6041. unreg: function() {
  6042. Ext.dd.ScrollManager.unregister(this.portal.body);
  6043. Ext.ux.Portal.DropZone.superclass.unreg.call(this);
  6044. }
  6045. });
  6046. Ext.ux.PortalColumn = Ext.extend(Ext.Container, {
  6047. layout : 'anchor',
  6048. //autoEl : 'div',//already defined by Ext.Component
  6049. defaultType : 'portlet',
  6050. cls : 'x-portal-column'
  6051. });
  6052. Ext.reg('portalcolumn', Ext.ux.PortalColumn);
  6053. Ext.ux.Portlet = Ext.extend(Ext.Panel, {
  6054. anchor : '100%',
  6055. frame : true,
  6056. collapsible : true,
  6057. draggable : true,
  6058. cls : 'x-portlet'
  6059. });
  6060. Ext.reg('portlet', Ext.ux.Portlet);
  6061. /**
  6062. * @class Ext.ux.ProgressBarPager
  6063. * @extends Object
  6064. * Plugin (ptype = 'tabclosemenu') for displaying a progressbar inside of a paging toolbar instead of plain text
  6065. *
  6066. * @ptype progressbarpager
  6067. * @constructor
  6068. * Create a new ItemSelector
  6069. * @param {Object} config Configuration options
  6070. * @xtype itemselector
  6071. */
  6072. Ext.ux.ProgressBarPager = Ext.extend(Object, {
  6073. /**
  6074. * @cfg {Integer} progBarWidth
  6075. * <p>The default progress bar width. Default is 225.</p>
  6076. */
  6077. progBarWidth : 225,
  6078. /**
  6079. * @cfg {String} defaultText
  6080. * <p>The text to display while the store is loading. Default is 'Loading...'</p>
  6081. */
  6082. defaultText : 'Loading...',
  6083. /**
  6084. * @cfg {Object} defaultAnimCfg
  6085. * <p>A {@link Ext.Fx Ext.Fx} configuration object. Default is { duration : 1, easing : 'bounceOut' }.</p>
  6086. */
  6087. defaultAnimCfg : {
  6088. duration : 1,
  6089. easing : 'bounceOut'
  6090. },
  6091. constructor : function(config) {
  6092. if (config) {
  6093. Ext.apply(this, config);
  6094. }
  6095. },
  6096. //public
  6097. init : function (parent) {
  6098. if(parent.displayInfo){
  6099. this.parent = parent;
  6100. var ind = parent.items.indexOf(parent.displayItem);
  6101. parent.remove(parent.displayItem, true);
  6102. this.progressBar = new Ext.ProgressBar({
  6103. text : this.defaultText,
  6104. width : this.progBarWidth,
  6105. animate : this.defaultAnimCfg
  6106. });
  6107. parent.displayItem = this.progressBar;
  6108. parent.add(parent.displayItem);
  6109. parent.doLayout();
  6110. Ext.apply(parent, this.parentOverrides);
  6111. this.progressBar.on('render', function(pb) {
  6112. pb.mon(pb.getEl().applyStyles('cursor:pointer'), 'click', this.handleProgressBarClick, this);
  6113. }, this, {single: true});
  6114. }
  6115. },
  6116. // private
  6117. // This method handles the click for the progress bar
  6118. handleProgressBarClick : function(e){
  6119. var parent = this.parent,
  6120. displayItem = parent.displayItem,
  6121. box = this.progressBar.getBox(),
  6122. xy = e.getXY(),
  6123. position = xy[0]-box.x,
  6124. pages = Math.ceil(parent.store.getTotalCount()/parent.pageSize),
  6125. newpage = Math.ceil(position/(displayItem.width/pages));
  6126. parent.changePage(newpage);
  6127. },
  6128. // private, overriddes
  6129. parentOverrides : {
  6130. // private
  6131. // This method updates the information via the progress bar.
  6132. updateInfo : function(){
  6133. if(this.displayItem){
  6134. var count = this.store.getCount(),
  6135. pgData = this.getPageData(),
  6136. pageNum = this.readPage(pgData),
  6137. msg = count == 0 ?
  6138. this.emptyMsg :
  6139. String.format(
  6140. this.displayMsg,
  6141. this.cursor+1, this.cursor+count, this.store.getTotalCount()
  6142. );
  6143. pageNum = pgData.activePage; ;
  6144. var pct = pageNum / pgData.pages;
  6145. this.displayItem.updateProgress(pct, msg, this.animate || this.defaultAnimConfig);
  6146. }
  6147. }
  6148. }
  6149. });
  6150. Ext.preg('progressbarpager', Ext.ux.ProgressBarPager);
  6151. Ext.ns('Ext.ux.grid');
  6152. /**
  6153. * @class Ext.ux.grid.RowEditor
  6154. * @extends Ext.Panel
  6155. * Plugin (ptype = 'roweditor') that adds the ability to rapidly edit full rows in a grid.
  6156. * A validation mode may be enabled which uses AnchorTips to notify the user of all
  6157. * validation errors at once.
  6158. *
  6159. * @ptype roweditor
  6160. */
  6161. Ext.ux.grid.RowEditor = Ext.extend(Ext.Panel, {
  6162. floating: true,
  6163. shadow: false,
  6164. layout: 'hbox',
  6165. cls: 'x-small-editor',
  6166. buttonAlign: 'center',
  6167. baseCls: 'x-row-editor',
  6168. elements: 'header,footer,body',
  6169. frameWidth: 5,
  6170. buttonPad: 3,
  6171. clicksToEdit: 'auto',
  6172. monitorValid: true,
  6173. focusDelay: 250,
  6174. errorSummary: true,
  6175. saveText: 'Save',
  6176. cancelText: 'Cancel',
  6177. commitChangesText: 'You need to commit or cancel your changes',
  6178. errorText: 'Errors',
  6179. defaults: {
  6180. normalWidth: true
  6181. },
  6182. initComponent: function(){
  6183. Ext.ux.grid.RowEditor.superclass.initComponent.call(this);
  6184. this.addEvents(
  6185. /**
  6186. * @event beforeedit
  6187. * Fired before the row editor is activated.
  6188. * If the listener returns <tt>false</tt> the editor will not be activated.
  6189. * @param {Ext.ux.grid.RowEditor} roweditor This object
  6190. * @param {Number} rowIndex The rowIndex of the row just edited
  6191. */
  6192. 'beforeedit',
  6193. /**
  6194. * @event canceledit
  6195. * Fired when the editor is cancelled.
  6196. * @param {Ext.ux.grid.RowEditor} roweditor This object
  6197. * @param {Boolean} forced True if the cancel button is pressed, false is the editor was invalid.
  6198. */
  6199. 'canceledit',
  6200. /**
  6201. * @event validateedit
  6202. * Fired after a row is edited and passes validation.
  6203. * If the listener returns <tt>false</tt> changes to the record will not be set.
  6204. * @param {Ext.ux.grid.RowEditor} roweditor This object
  6205. * @param {Object} changes Object with changes made to the record.
  6206. * @param {Ext.data.Record} r The Record that was edited.
  6207. * @param {Number} rowIndex The rowIndex of the row just edited
  6208. */
  6209. 'validateedit',
  6210. /**
  6211. * @event afteredit
  6212. * Fired after a row is edited and passes validation. This event is fired
  6213. * after the store's update event is fired with this edit.
  6214. * @param {Ext.ux.grid.RowEditor} roweditor This object
  6215. * @param {Object} changes Object with changes made to the record.
  6216. * @param {Ext.data.Record} r The Record that was edited.
  6217. * @param {Number} rowIndex The rowIndex of the row just edited
  6218. */
  6219. 'afteredit'
  6220. );
  6221. },
  6222. init: function(grid){
  6223. this.grid = grid;
  6224. this.ownerCt = grid;
  6225. if(this.clicksToEdit === 2){
  6226. grid.on('rowdblclick', this.onRowDblClick, this);
  6227. }else{
  6228. grid.on('rowclick', this.onRowClick, this);
  6229. if(Ext.isIE){
  6230. grid.on('rowdblclick', this.onRowDblClick, this);
  6231. }
  6232. }
  6233. // stopEditing without saving when a record is removed from Store.
  6234. grid.getStore().on('remove', function() {
  6235. this.stopEditing(false);
  6236. },this);
  6237. grid.on({
  6238. scope: this,
  6239. keydown: this.onGridKey,
  6240. columnresize: this.verifyLayout,
  6241. columnmove: this.refreshFields,
  6242. reconfigure: this.refreshFields,
  6243. beforedestroy : this.beforedestroy,
  6244. destroy : this.destroy,
  6245. bodyscroll: {
  6246. buffer: 250,
  6247. fn: this.positionButtons
  6248. }
  6249. });
  6250. grid.getColumnModel().on('hiddenchange', this.verifyLayout, this, {delay:1});
  6251. grid.getView().on('refresh', this.stopEditing.createDelegate(this, []));
  6252. },
  6253. beforedestroy: function() {
  6254. this.stopMonitoring();
  6255. this.grid.getStore().un('remove', this.onStoreRemove, this);
  6256. this.stopEditing(false);
  6257. Ext.destroy(this.btns, this.tooltip);
  6258. },
  6259. refreshFields: function(){
  6260. this.initFields();
  6261. this.verifyLayout();
  6262. },
  6263. isDirty: function(){
  6264. var dirty;
  6265. this.items.each(function(f){
  6266. if(String(this.values[f.id]) !== String(f.getValue())){
  6267. dirty = true;
  6268. return false;
  6269. }
  6270. }, this);
  6271. return dirty;
  6272. },
  6273. startEditing: function(rowIndex, doFocus){
  6274. if(this.editing && this.isDirty()){
  6275. this.showTooltip(this.commitChangesText);
  6276. return;
  6277. }
  6278. if(Ext.isObject(rowIndex)){
  6279. rowIndex = this.grid.getStore().indexOf(rowIndex);
  6280. }
  6281. if(this.fireEvent('beforeedit', this, rowIndex) !== false){
  6282. this.editing = true;
  6283. var g = this.grid, view = g.getView(),
  6284. row = view.getRow(rowIndex),
  6285. record = g.store.getAt(rowIndex);
  6286. this.record = record;
  6287. this.rowIndex = rowIndex;
  6288. this.values = {};
  6289. if(!this.rendered){
  6290. this.render(view.getEditorParent());
  6291. }
  6292. var w = Ext.fly(row).getWidth();
  6293. this.setSize(w);
  6294. if(!this.initialized){
  6295. this.initFields();
  6296. }
  6297. var cm = g.getColumnModel(), fields = this.items.items, f, val;
  6298. for(var i = 0, len = cm.getColumnCount(); i < len; i++){
  6299. val = this.preEditValue(record, cm.getDataIndex(i));
  6300. f = fields[i];
  6301. f.setValue(val);
  6302. this.values[f.id] = Ext.isEmpty(val) ? '' : val;
  6303. }
  6304. this.verifyLayout(true);
  6305. if(!this.isVisible()){
  6306. this.setPagePosition(Ext.fly(row).getXY());
  6307. } else{
  6308. this.el.setXY(Ext.fly(row).getXY(), {duration:0.15});
  6309. }
  6310. if(!this.isVisible()){
  6311. this.show().doLayout();
  6312. }
  6313. if(doFocus !== false){
  6314. this.doFocus.defer(this.focusDelay, this);
  6315. }
  6316. }
  6317. },
  6318. stopEditing : function(saveChanges){
  6319. this.editing = false;
  6320. if(!this.isVisible()){
  6321. return;
  6322. }
  6323. if(saveChanges === false || !this.isValid()){
  6324. this.hide();
  6325. this.fireEvent('canceledit', this, saveChanges === false);
  6326. return;
  6327. }
  6328. var changes = {},
  6329. r = this.record,
  6330. hasChange = false,
  6331. cm = this.grid.colModel,
  6332. fields = this.items.items;
  6333. for(var i = 0, len = cm.getColumnCount(); i < len; i++){
  6334. if(!cm.isHidden(i)){
  6335. var dindex = cm.getDataIndex(i);
  6336. if(!Ext.isEmpty(dindex)){
  6337. var oldValue = r.data[dindex],
  6338. value = this.postEditValue(fields[i].getValue(), oldValue, r, dindex);
  6339. if(String(oldValue) !== String(value)){
  6340. changes[dindex] = value;
  6341. hasChange = true;
  6342. }
  6343. }
  6344. }
  6345. }
  6346. if(hasChange && this.fireEvent('validateedit', this, changes, r, this.rowIndex) !== false){
  6347. r.beginEdit();
  6348. Ext.iterate(changes, function(name, value){
  6349. r.set(name, value);
  6350. });
  6351. r.endEdit();
  6352. this.fireEvent('afteredit', this, changes, r, this.rowIndex);
  6353. } else {
  6354. this.fireEvent('canceledit', this, false);
  6355. }
  6356. this.hide();
  6357. },
  6358. verifyLayout: function(force){
  6359. if(this.el && (this.isVisible() || force === true)){
  6360. var row = this.grid.getView().getRow(this.rowIndex);
  6361. this.setSize(Ext.fly(row).getWidth(), Ext.isIE ? Ext.fly(row).getHeight() + 9 : undefined);
  6362. var cm = this.grid.colModel, fields = this.items.items;
  6363. for(var i = 0, len = cm.getColumnCount(); i < len; i++){
  6364. if(!cm.isHidden(i)){
  6365. var adjust = 0;
  6366. if(i === (len - 1)){
  6367. adjust += 3; // outer padding
  6368. } else{
  6369. adjust += 1;
  6370. }
  6371. fields[i].show();
  6372. fields[i].setWidth(cm.getColumnWidth(i) - adjust);
  6373. } else{
  6374. fields[i].hide();
  6375. }
  6376. }
  6377. this.doLayout();
  6378. this.positionButtons();
  6379. }
  6380. },
  6381. slideHide : function(){
  6382. this.hide();
  6383. },
  6384. initFields: function(){
  6385. var cm = this.grid.getColumnModel(), pm = Ext.layout.ContainerLayout.prototype.parseMargins;
  6386. this.removeAll(false);
  6387. for(var i = 0, len = cm.getColumnCount(); i < len; i++){
  6388. var c = cm.getColumnAt(i),
  6389. ed = c.getEditor();
  6390. if(!ed){
  6391. ed = c.displayEditor || new Ext.form.DisplayField();
  6392. }
  6393. if(i == 0){
  6394. ed.margins = pm('0 1 2 1');
  6395. } else if(i == len - 1){
  6396. ed.margins = pm('0 0 2 1');
  6397. } else{
  6398. if (Ext.isIE) {
  6399. ed.margins = pm('0 0 2 0');
  6400. }
  6401. else {
  6402. ed.margins = pm('0 1 2 0');
  6403. }
  6404. }
  6405. ed.setWidth(cm.getColumnWidth(i));
  6406. ed.column = c;
  6407. if(ed.ownerCt !== this){
  6408. ed.on('focus', this.ensureVisible, this);
  6409. ed.on('specialkey', this.onKey, this);
  6410. }
  6411. this.insert(i, ed);
  6412. }
  6413. this.initialized = true;
  6414. },
  6415. onKey: function(f, e){
  6416. if(e.getKey() === e.ENTER){
  6417. this.stopEditing(true);
  6418. e.stopPropagation();
  6419. }
  6420. },
  6421. onGridKey: function(e){
  6422. if(e.getKey() === e.ENTER && !this.isVisible()){
  6423. var r = this.grid.getSelectionModel().getSelected();
  6424. if(r){
  6425. var index = this.grid.store.indexOf(r);
  6426. this.startEditing(index);
  6427. e.stopPropagation();
  6428. }
  6429. }
  6430. },
  6431. ensureVisible: function(editor){
  6432. if(this.isVisible()){
  6433. this.grid.getView().ensureVisible(this.rowIndex, this.grid.colModel.getIndexById(editor.column.id), true);
  6434. }
  6435. },
  6436. onRowClick: function(g, rowIndex, e){
  6437. if(this.clicksToEdit == 'auto'){
  6438. var li = this.lastClickIndex;
  6439. this.lastClickIndex = rowIndex;
  6440. if(li != rowIndex && !this.isVisible()){
  6441. return;
  6442. }
  6443. }
  6444. this.startEditing(rowIndex, false);
  6445. this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
  6446. },
  6447. onRowDblClick: function(g, rowIndex, e){
  6448. this.startEditing(rowIndex, false);
  6449. this.doFocus.defer(this.focusDelay, this, [e.getPoint()]);
  6450. },
  6451. onRender: function(){
  6452. Ext.ux.grid.RowEditor.superclass.onRender.apply(this, arguments);
  6453. this.el.swallowEvent(['keydown', 'keyup', 'keypress']);
  6454. this.btns = new Ext.Panel({
  6455. baseCls: 'x-plain',
  6456. cls: 'x-btns',
  6457. elements:'body',
  6458. layout: 'table',
  6459. width: (this.minButtonWidth * 2) + (this.frameWidth * 2) + (this.buttonPad * 4), // width must be specified for IE
  6460. items: [{
  6461. ref: 'saveBtn',
  6462. itemId: 'saveBtn',
  6463. xtype: 'button',
  6464. text: this.saveText,
  6465. width: this.minButtonWidth,
  6466. handler: this.stopEditing.createDelegate(this, [true])
  6467. }, {
  6468. xtype: 'button',
  6469. text: this.cancelText,
  6470. width: this.minButtonWidth,
  6471. handler: this.stopEditing.createDelegate(this, [false])
  6472. }]
  6473. });
  6474. this.btns.render(this.bwrap);
  6475. },
  6476. afterRender: function(){
  6477. Ext.ux.grid.RowEditor.superclass.afterRender.apply(this, arguments);
  6478. this.positionButtons();
  6479. if(this.monitorValid){
  6480. this.startMonitoring();
  6481. }
  6482. },
  6483. onShow: function(){
  6484. if(this.monitorValid){
  6485. this.startMonitoring();
  6486. }
  6487. Ext.ux.grid.RowEditor.superclass.onShow.apply(this, arguments);
  6488. },
  6489. onHide: function(){
  6490. Ext.ux.grid.RowEditor.superclass.onHide.apply(this, arguments);
  6491. this.stopMonitoring();
  6492. this.grid.getView().focusRow(this.rowIndex);
  6493. },
  6494. positionButtons: function(){
  6495. if(this.btns){
  6496. var g = this.grid,
  6497. h = this.el.dom.clientHeight,
  6498. view = g.getView(),
  6499. scroll = view.scroller.dom.scrollLeft,
  6500. bw = this.btns.getWidth(),
  6501. width = Math.min(g.getWidth(), g.getColumnModel().getTotalWidth());
  6502. this.btns.el.shift({left: (width/2)-(bw/2)+scroll, top: h - 2, stopFx: true, duration:0.2});
  6503. }
  6504. },
  6505. // private
  6506. preEditValue : function(r, field){
  6507. var value = r.data[field];
  6508. return this.autoEncode && typeof value === 'string' ? Ext.util.Format.htmlDecode(value) : value;
  6509. },
  6510. // private
  6511. postEditValue : function(value, originalValue, r, field){
  6512. return this.autoEncode && typeof value == 'string' ? Ext.util.Format.htmlEncode(value) : value;
  6513. },
  6514. doFocus: function(pt){
  6515. if(this.isVisible()){
  6516. var index = 0,
  6517. cm = this.grid.getColumnModel(),
  6518. c;
  6519. if(pt){
  6520. index = this.getTargetColumnIndex(pt);
  6521. }
  6522. for(var i = index||0, len = cm.getColumnCount(); i < len; i++){
  6523. c = cm.getColumnAt(i);
  6524. if(!c.hidden && c.getEditor()){
  6525. c.getEditor().focus();
  6526. break;
  6527. }
  6528. }
  6529. }
  6530. },
  6531. getTargetColumnIndex: function(pt){
  6532. var grid = this.grid,
  6533. v = grid.view,
  6534. x = pt.left,
  6535. cms = grid.colModel.config,
  6536. i = 0,
  6537. match = false;
  6538. for(var len = cms.length, c; c = cms[i]; i++){
  6539. if(!c.hidden){
  6540. if(Ext.fly(v.getHeaderCell(i)).getRegion().right >= x){
  6541. match = i;
  6542. break;
  6543. }
  6544. }
  6545. }
  6546. return match;
  6547. },
  6548. startMonitoring : function(){
  6549. if(!this.bound && this.monitorValid){
  6550. this.bound = true;
  6551. Ext.TaskMgr.start({
  6552. run : this.bindHandler,
  6553. interval : this.monitorPoll || 200,
  6554. scope: this
  6555. });
  6556. }
  6557. },
  6558. stopMonitoring : function(){
  6559. this.bound = false;
  6560. if(this.tooltip){
  6561. this.tooltip.hide();
  6562. }
  6563. },
  6564. isValid: function(){
  6565. var valid = true;
  6566. this.items.each(function(f){
  6567. if(!f.isValid(true)){
  6568. valid = false;
  6569. return false;
  6570. }
  6571. });
  6572. return valid;
  6573. },
  6574. // private
  6575. bindHandler : function(){
  6576. if(!this.bound){
  6577. return false; // stops binding
  6578. }
  6579. var valid = this.isValid();
  6580. if(!valid && this.errorSummary){
  6581. this.showTooltip(this.getErrorText().join(''));
  6582. }
  6583. this.btns.saveBtn.setDisabled(!valid);
  6584. this.fireEvent('validation', this, valid);
  6585. },
  6586. lastVisibleColumn : function() {
  6587. var i = this.items.getCount() - 1,
  6588. c;
  6589. for(; i >= 0; i--) {
  6590. c = this.items.items[i];
  6591. if (!c.hidden) {
  6592. return c;
  6593. }
  6594. }
  6595. },
  6596. showTooltip: function(msg){
  6597. var t = this.tooltip;
  6598. if(!t){
  6599. t = this.tooltip = new Ext.ToolTip({
  6600. maxWidth: 600,
  6601. cls: 'errorTip',
  6602. width: 300,
  6603. title: this.errorText,
  6604. autoHide: false,
  6605. anchor: 'left',
  6606. anchorToTarget: true,
  6607. mouseOffset: [40,0]
  6608. });
  6609. }
  6610. var v = this.grid.getView(),
  6611. top = parseInt(this.el.dom.style.top, 10),
  6612. scroll = v.scroller.dom.scrollTop,
  6613. h = this.el.getHeight();
  6614. if(top + h >= scroll){
  6615. t.initTarget(this.lastVisibleColumn().getEl());
  6616. if(!t.rendered){
  6617. t.show();
  6618. t.hide();
  6619. }
  6620. t.body.update(msg);
  6621. t.doAutoWidth(20);
  6622. t.show();
  6623. }else if(t.rendered){
  6624. t.hide();
  6625. }
  6626. },
  6627. getErrorText: function(){
  6628. var data = ['<ul>'];
  6629. this.items.each(function(f){
  6630. if(!f.isValid(true)){
  6631. data.push('<li>', f.getActiveError(), '</li>');
  6632. }
  6633. });
  6634. data.push('</ul>');
  6635. return data;
  6636. }
  6637. });
  6638. Ext.preg('roweditor', Ext.ux.grid.RowEditor);
  6639. Ext.ns('Ext.ux.grid');
  6640. /**
  6641. * @class Ext.ux.grid.RowExpander
  6642. * @extends Ext.util.Observable
  6643. * Plugin (ptype = 'rowexpander') that adds the ability to have a Column in a grid which enables
  6644. * a second row body which expands/contracts. The expand/contract behavior is configurable to react
  6645. * on clicking of the column, double click of the row, and/or hitting enter while a row is selected.
  6646. *
  6647. * @ptype rowexpander
  6648. */
  6649. Ext.ux.grid.RowExpander = Ext.extend(Ext.util.Observable, {
  6650. /**
  6651. * @cfg {Boolean} expandOnEnter
  6652. * <tt>true</tt> to toggle selected row(s) between expanded/collapsed when the enter
  6653. * key is pressed (defaults to <tt>true</tt>).
  6654. */
  6655. expandOnEnter : true,
  6656. /**
  6657. * @cfg {Boolean} expandOnDblClick
  6658. * <tt>true</tt> to toggle a row between expanded/collapsed when double clicked
  6659. * (defaults to <tt>true</tt>).
  6660. */
  6661. expandOnDblClick : true,
  6662. header : '',
  6663. width : 20,
  6664. sortable : false,
  6665. fixed : true,
  6666. hideable: false,
  6667. menuDisabled : true,
  6668. dataIndex : '',
  6669. id : 'expander',
  6670. lazyRender : true,
  6671. enableCaching : true,
  6672. constructor: function(config){
  6673. Ext.apply(this, config);
  6674. this.addEvents({
  6675. /**
  6676. * @event beforeexpand
  6677. * Fires before the row expands. Have the listener return false to prevent the row from expanding.
  6678. * @param {Object} this RowExpander object.
  6679. * @param {Object} Ext.data.Record Record for the selected row.
  6680. * @param {Object} body body element for the secondary row.
  6681. * @param {Number} rowIndex The current row index.
  6682. */
  6683. beforeexpand: true,
  6684. /**
  6685. * @event expand
  6686. * Fires after the row expands.
  6687. * @param {Object} this RowExpander object.
  6688. * @param {Object} Ext.data.Record Record for the selected row.
  6689. * @param {Object} body body element for the secondary row.
  6690. * @param {Number} rowIndex The current row index.
  6691. */
  6692. expand: true,
  6693. /**
  6694. * @event beforecollapse
  6695. * Fires before the row collapses. Have the listener return false to prevent the row from collapsing.
  6696. * @param {Object} this RowExpander object.
  6697. * @param {Object} Ext.data.Record Record for the selected row.
  6698. * @param {Object} body body element for the secondary row.
  6699. * @param {Number} rowIndex The current row index.
  6700. */
  6701. beforecollapse: true,
  6702. /**
  6703. * @event collapse
  6704. * Fires after the row collapses.
  6705. * @param {Object} this RowExpander object.
  6706. * @param {Object} Ext.data.Record Record for the selected row.
  6707. * @param {Object} body body element for the secondary row.
  6708. * @param {Number} rowIndex The current row index.
  6709. */
  6710. collapse: true
  6711. });
  6712. Ext.ux.grid.RowExpander.superclass.constructor.call(this);
  6713. if(this.tpl){
  6714. if(typeof this.tpl == 'string'){
  6715. this.tpl = new Ext.Template(this.tpl);
  6716. }
  6717. this.tpl.compile();
  6718. }
  6719. this.state = {};
  6720. this.bodyContent = {};
  6721. },
  6722. getRowClass : function(record, rowIndex, p, ds){
  6723. p.cols = p.cols-1;
  6724. var content = this.bodyContent[record.id];
  6725. if(!content && !this.lazyRender){
  6726. content = this.getBodyContent(record, rowIndex);
  6727. }
  6728. if(content){
  6729. p.body = content;
  6730. }
  6731. return this.state[record.id] ? 'x-grid3-row-expanded' : 'x-grid3-row-collapsed';
  6732. },
  6733. init : function(grid){
  6734. this.grid = grid;
  6735. var view = grid.getView();
  6736. view.getRowClass = this.getRowClass.createDelegate(this);
  6737. view.enableRowBody = true;
  6738. grid.on('render', this.onRender, this);
  6739. grid.on('destroy', this.onDestroy, this);
  6740. },
  6741. // @private
  6742. onRender: function() {
  6743. var grid = this.grid;
  6744. var mainBody = grid.getView().mainBody;
  6745. mainBody.on('mousedown', this.onMouseDown, this, {delegate: '.x-grid3-row-expander'});
  6746. if (this.expandOnEnter) {
  6747. this.keyNav = new Ext.KeyNav(this.grid.getGridEl(), {
  6748. 'enter' : this.onEnter,
  6749. scope: this
  6750. });
  6751. }
  6752. if (this.expandOnDblClick) {
  6753. grid.on('rowdblclick', this.onRowDblClick, this);
  6754. }
  6755. },
  6756. // @private
  6757. onDestroy: function() {
  6758. if(this.keyNav){
  6759. this.keyNav.disable();
  6760. delete this.keyNav;
  6761. }
  6762. /*
  6763. * A majority of the time, the plugin will be destroyed along with the grid,
  6764. * which means the mainBody won't be available. On the off chance that the plugin
  6765. * isn't destroyed with the grid, take care of removing the listener.
  6766. */
  6767. var mainBody = this.grid.getView().mainBody;
  6768. if(mainBody){
  6769. mainBody.un('mousedown', this.onMouseDown, this);
  6770. }
  6771. },
  6772. // @private
  6773. onRowDblClick: function(grid, rowIdx, e) {
  6774. this.toggleRow(rowIdx);
  6775. },
  6776. onEnter: function(e) {
  6777. var g = this.grid;
  6778. var sm = g.getSelectionModel();
  6779. var sels = sm.getSelections();
  6780. for (var i = 0, len = sels.length; i < len; i++) {
  6781. var rowIdx = g.getStore().indexOf(sels[i]);
  6782. this.toggleRow(rowIdx);
  6783. }
  6784. },
  6785. getBodyContent : function(record, index){
  6786. if(!this.enableCaching){
  6787. return this.tpl.apply(record.data);
  6788. }
  6789. var content = this.bodyContent[record.id];
  6790. if(!content){
  6791. content = this.tpl.apply(record.data);
  6792. this.bodyContent[record.id] = content;
  6793. }
  6794. return content;
  6795. },
  6796. onMouseDown : function(e, t){
  6797. e.stopEvent();
  6798. var row = e.getTarget('.x-grid3-row');
  6799. this.toggleRow(row);
  6800. },
  6801. renderer : function(v, p, record){
  6802. p.cellAttr = 'rowspan="2"';
  6803. return '<div class="x-grid3-row-expander">&#160;</div>';
  6804. },
  6805. beforeExpand : function(record, body, rowIndex){
  6806. if(this.fireEvent('beforeexpand', this, record, body, rowIndex) !== false){
  6807. if(this.tpl && this.lazyRender){
  6808. body.innerHTML = this.getBodyContent(record, rowIndex);
  6809. }
  6810. return true;
  6811. }else{
  6812. return false;
  6813. }
  6814. },
  6815. toggleRow : function(row){
  6816. if(typeof row == 'number'){
  6817. row = this.grid.view.getRow(row);
  6818. }
  6819. this[Ext.fly(row).hasClass('x-grid3-row-collapsed') ? 'expandRow' : 'collapseRow'](row);
  6820. },
  6821. expandRow : function(row){
  6822. if(typeof row == 'number'){
  6823. row = this.grid.view.getRow(row);
  6824. }
  6825. var record = this.grid.store.getAt(row.rowIndex);
  6826. var body = Ext.DomQuery.selectNode('tr:nth(2) div.x-grid3-row-body', row);
  6827. if(this.beforeExpand(record, body, row.rowIndex)){
  6828. this.state[record.id] = true;
  6829. Ext.fly(row).replaceClass('x-grid3-row-collapsed', 'x-grid3-row-expanded');
  6830. this.fireEvent('expand', this, record, body, row.rowIndex);
  6831. }
  6832. },
  6833. collapseRow : function(row){
  6834. if(typeof row == 'number'){
  6835. row = this.grid.view.getRow(row);
  6836. }
  6837. var record = this.grid.store.getAt(row.rowIndex);
  6838. var body = Ext.fly(row).child('tr:nth(1) div.x-grid3-row-body', true);
  6839. if(this.fireEvent('beforecollapse', this, record, body, row.rowIndex) !== false){
  6840. this.state[record.id] = false;
  6841. Ext.fly(row).replaceClass('x-grid3-row-expanded', 'x-grid3-row-collapsed');
  6842. this.fireEvent('collapse', this, record, body, row.rowIndex);
  6843. }
  6844. }
  6845. });
  6846. Ext.preg('rowexpander', Ext.ux.grid.RowExpander);
  6847. //backwards compat
  6848. Ext.grid.RowExpander = Ext.ux.grid.RowExpander;// We are adding these custom layouts to a namespace that does not
  6849. // exist by default in Ext, so we have to add the namespace first:
  6850. Ext.ns('Ext.ux.layout');
  6851. /**
  6852. * @class Ext.ux.layout.RowLayout
  6853. * @extends Ext.layout.ContainerLayout
  6854. * <p>This is the layout style of choice for creating structural layouts in a multi-row format where the height of
  6855. * each row can be specified as a percentage or fixed height. Row widths can also be fixed, percentage or auto.
  6856. * This class is intended to be extended or created via the layout:'ux.row' {@link Ext.Container#layout} config,
  6857. * and should generally not need to be created directly via the new keyword.</p>
  6858. * <p>RowLayout does not have any direct config options (other than inherited ones), but it does support a
  6859. * specific config property of <b><tt>rowHeight</tt></b> that can be included in the config of any panel added to it. The
  6860. * layout will use the rowHeight (if present) or height of each panel during layout to determine how to size each panel.
  6861. * If height or rowHeight is not specified for a given panel, its height will default to the panel's height (or auto).</p>
  6862. * <p>The height property is always evaluated as pixels, and must be a number greater than or equal to 1.
  6863. * The rowHeight property is always evaluated as a percentage, and must be a decimal value greater than 0 and
  6864. * less than 1 (e.g., .25).</p>
  6865. * <p>The basic rules for specifying row heights are pretty simple. The logic makes two passes through the
  6866. * set of contained panels. During the first layout pass, all panels that either have a fixed height or none
  6867. * specified (auto) are skipped, but their heights are subtracted from the overall container height. During the second
  6868. * pass, all panels with rowHeights are assigned pixel heights in proportion to their percentages based on
  6869. * the total <b>remaining</b> container height. In other words, percentage height panels are designed to fill the space
  6870. * left over by all the fixed-height and/or auto-height panels. Because of this, while you can specify any number of rows
  6871. * with different percentages, the rowHeights must always add up to 1 (or 100%) when added together, otherwise your
  6872. * layout may not render as expected. Example usage:</p>
  6873. * <pre><code>
  6874. // All rows are percentages -- they must add up to 1
  6875. var p = new Ext.Panel({
  6876. title: 'Row Layout - Percentage Only',
  6877. layout:'ux.row',
  6878. items: [{
  6879. title: 'Row 1',
  6880. rowHeight: .25
  6881. },{
  6882. title: 'Row 2',
  6883. rowHeight: .6
  6884. },{
  6885. title: 'Row 3',
  6886. rowHeight: .15
  6887. }]
  6888. });
  6889. // Mix of height and rowHeight -- all rowHeight values must add
  6890. // up to 1. The first row will take up exactly 120px, and the last two
  6891. // rows will fill the remaining container height.
  6892. var p = new Ext.Panel({
  6893. title: 'Row Layout - Mixed',
  6894. layout:'ux.row',
  6895. items: [{
  6896. title: 'Row 1',
  6897. height: 120,
  6898. // standard panel widths are still supported too:
  6899. width: '50%' // or 200
  6900. },{
  6901. title: 'Row 2',
  6902. rowHeight: .8,
  6903. width: 300
  6904. },{
  6905. title: 'Row 3',
  6906. rowHeight: .2
  6907. }]
  6908. });
  6909. </code></pre>
  6910. */
  6911. Ext.ux.layout.RowLayout = Ext.extend(Ext.layout.ContainerLayout, {
  6912. // private
  6913. monitorResize:true,
  6914. type: 'row',
  6915. // private
  6916. allowContainerRemove: false,
  6917. // private
  6918. isValidParent : function(c, target){
  6919. return this.innerCt && c.getPositionEl().dom.parentNode == this.innerCt.dom;
  6920. },
  6921. getLayoutTargetSize : function() {
  6922. var target = this.container.getLayoutTarget(), ret;
  6923. if (target) {
  6924. ret = target.getViewSize();
  6925. // IE in strict mode will return a height of 0 on the 1st pass of getViewSize.
  6926. // Use getStyleSize to verify the 0 height, the adjustment pass will then work properly
  6927. // with getViewSize
  6928. if (Ext.isIE && Ext.isStrict && ret.height == 0){
  6929. ret = target.getStyleSize();
  6930. }
  6931. ret.width -= target.getPadding('lr');
  6932. ret.height -= target.getPadding('tb');
  6933. }
  6934. return ret;
  6935. },
  6936. renderAll : function(ct, target) {
  6937. if(!this.innerCt){
  6938. // the innerCt prevents wrapping and shuffling while
  6939. // the container is resizing
  6940. this.innerCt = target.createChild({cls:'x-column-inner'});
  6941. this.innerCt.createChild({cls:'x-clear'});
  6942. }
  6943. Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
  6944. },
  6945. // private
  6946. onLayout : function(ct, target){
  6947. var rs = ct.items.items,
  6948. len = rs.length,
  6949. r,
  6950. m,
  6951. i,
  6952. margins = [];
  6953. this.renderAll(ct, target);
  6954. var size = this.getLayoutTargetSize();
  6955. if(size.width < 1 && size.height < 1){ // display none?
  6956. return;
  6957. }
  6958. var h = size.height,
  6959. ph = h;
  6960. this.innerCt.setSize({height:h});
  6961. // some rows can be percentages while others are fixed
  6962. // so we need to make 2 passes
  6963. for(i = 0; i < len; i++){
  6964. r = rs[i];
  6965. m = r.getPositionEl().getMargins('tb');
  6966. margins[i] = m;
  6967. if(!r.rowHeight){
  6968. ph -= (r.getHeight() + m);
  6969. }
  6970. }
  6971. ph = ph < 0 ? 0 : ph;
  6972. for(i = 0; i < len; i++){
  6973. r = rs[i];
  6974. m = margins[i];
  6975. if(r.rowHeight){
  6976. r.setSize({height: Math.floor(r.rowHeight*ph) - m});
  6977. }
  6978. }
  6979. // Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
  6980. // spaces were accounted for properly. If not, re-layout.
  6981. if (Ext.isIE) {
  6982. if (i = target.getStyle('overflow') && i != 'hidden' && !this.adjustmentPass) {
  6983. var ts = this.getLayoutTargetSize();
  6984. if (ts.width != size.width){
  6985. this.adjustmentPass = true;
  6986. this.onLayout(ct, target);
  6987. }
  6988. }
  6989. }
  6990. delete this.adjustmentPass;
  6991. }
  6992. /**
  6993. * @property activeItem
  6994. * @hide
  6995. */
  6996. });
  6997. Ext.Container.LAYOUTS['ux.row'] = Ext.ux.layout.RowLayout;
  6998. Ext.ns('Ext.ux.form');
  6999. Ext.ux.form.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
  7000. initComponent : function(){
  7001. Ext.ux.form.SearchField.superclass.initComponent.call(this);
  7002. this.on('specialkey', function(f, e){
  7003. if(e.getKey() == e.ENTER){
  7004. this.onTrigger2Click();
  7005. }
  7006. }, this);
  7007. },
  7008. validationEvent:false,
  7009. validateOnBlur:false,
  7010. trigger1Class:'x-form-clear-trigger',
  7011. trigger2Class:'x-form-search-trigger',
  7012. hideTrigger1:true,
  7013. width:180,
  7014. hasSearch : false,
  7015. paramName : 'query',
  7016. onTrigger1Click : function(){
  7017. if(this.hasSearch){
  7018. this.el.dom.value = '';
  7019. var o = {start: 0};
  7020. this.store.baseParams = this.store.baseParams || {};
  7021. this.store.baseParams[this.paramName] = '';
  7022. this.store.reload({params:o});
  7023. this.triggers[0].hide();
  7024. this.hasSearch = false;
  7025. }
  7026. },
  7027. onTrigger2Click : function(){
  7028. var v = this.getRawValue();
  7029. if(v.length < 1){
  7030. this.onTrigger1Click();
  7031. return;
  7032. }
  7033. var o = {start: 0};
  7034. this.store.baseParams = this.store.baseParams || {};
  7035. this.store.baseParams[this.paramName] = v;
  7036. this.store.reload({params:o});
  7037. this.hasSearch = true;
  7038. this.triggers[0].show();
  7039. }
  7040. });Ext.ns('Ext.ux.form');
  7041. /**
  7042. * @class Ext.ux.form.SelectBox
  7043. * @extends Ext.form.ComboBox
  7044. * <p>Makes a ComboBox more closely mimic an HTML SELECT. Supports clicking and dragging
  7045. * through the list, with item selection occurring when the mouse button is released.
  7046. * When used will automatically set {@link #editable} to false and call {@link Ext.Element#unselectable}
  7047. * on inner elements. Re-enabling editable after calling this will NOT work.</p>
  7048. * @author Corey Gilmore http://extjs.com/forum/showthread.php?t=6392
  7049. * @history 2007-07-08 jvs
  7050. * Slight mods for Ext 2.0
  7051. * @xtype selectbox
  7052. */
  7053. Ext.ux.form.SelectBox = Ext.extend(Ext.form.ComboBox, {
  7054. constructor: function(config){
  7055. this.searchResetDelay = 1000;
  7056. config = config || {};
  7057. config = Ext.apply(config || {}, {
  7058. editable: false,
  7059. forceSelection: true,
  7060. rowHeight: false,
  7061. lastSearchTerm: false,
  7062. triggerAction: 'all',
  7063. mode: 'local'
  7064. });
  7065. Ext.ux.form.SelectBox.superclass.constructor.apply(this, arguments);
  7066. this.lastSelectedIndex = this.selectedIndex || 0;
  7067. },
  7068. initEvents : function(){
  7069. Ext.ux.form.SelectBox.superclass.initEvents.apply(this, arguments);
  7070. // you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE
  7071. this.el.on('keydown', this.keySearch, this, true);
  7072. this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);
  7073. },
  7074. keySearch : function(e, target, options) {
  7075. var raw = e.getKey();
  7076. var key = String.fromCharCode(raw);
  7077. var startIndex = 0;
  7078. if( !this.store.getCount() ) {
  7079. return;
  7080. }
  7081. switch(raw) {
  7082. case Ext.EventObject.HOME:
  7083. e.stopEvent();
  7084. this.selectFirst();
  7085. return;
  7086. case Ext.EventObject.END:
  7087. e.stopEvent();
  7088. this.selectLast();
  7089. return;
  7090. case Ext.EventObject.PAGEDOWN:
  7091. this.selectNextPage();
  7092. e.stopEvent();
  7093. return;
  7094. case Ext.EventObject.PAGEUP:
  7095. this.selectPrevPage();
  7096. e.stopEvent();
  7097. return;
  7098. }
  7099. // skip special keys other than the shift key
  7100. if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {
  7101. return;
  7102. }
  7103. if( this.lastSearchTerm == key ) {
  7104. startIndex = this.lastSelectedIndex;
  7105. }
  7106. this.search(this.displayField, key, startIndex);
  7107. this.cshTask.delay(this.searchResetDelay);
  7108. },
  7109. onRender : function(ct, position) {
  7110. this.store.on('load', this.calcRowsPerPage, this);
  7111. Ext.ux.form.SelectBox.superclass.onRender.apply(this, arguments);
  7112. if( this.mode == 'local' ) {
  7113. this.initList();
  7114. this.calcRowsPerPage();
  7115. }
  7116. },
  7117. onSelect : function(record, index, skipCollapse){
  7118. if(this.fireEvent('beforeselect', this, record, index) !== false){
  7119. this.setValue(record.data[this.valueField || this.displayField]);
  7120. if( !skipCollapse ) {
  7121. this.collapse();
  7122. }
  7123. this.lastSelectedIndex = index + 1;
  7124. this.fireEvent('select', this, record, index);
  7125. }
  7126. },
  7127. afterRender : function() {
  7128. Ext.ux.form.SelectBox.superclass.afterRender.apply(this, arguments);
  7129. if(Ext.isWebKit) {
  7130. this.el.swallowEvent('mousedown', true);
  7131. }
  7132. this.el.unselectable();
  7133. this.innerList.unselectable();
  7134. this.trigger.unselectable();
  7135. this.innerList.on('mouseup', function(e, target, options) {
  7136. if( target.id && target.id == this.innerList.id ) {
  7137. return;
  7138. }
  7139. this.onViewClick();
  7140. }, this);
  7141. this.mun(this.view, 'containerclick', this.onViewClick, this);
  7142. this.mun(this.view, 'click', this.onViewClick, this);
  7143. this.innerList.on('mouseover', function(e, target, options) {
  7144. if( target.id && target.id == this.innerList.id ) {
  7145. return;
  7146. }
  7147. this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;
  7148. this.cshTask.delay(this.searchResetDelay);
  7149. }, this);
  7150. this.trigger.un('click', this.onTriggerClick, this);
  7151. this.trigger.on('mousedown', function(e, target, options) {
  7152. e.preventDefault();
  7153. this.onTriggerClick();
  7154. }, this);
  7155. this.on('collapse', function(e, target, options) {
  7156. Ext.getDoc().un('mouseup', this.collapseIf, this);
  7157. }, this, true);
  7158. this.on('expand', function(e, target, options) {
  7159. Ext.getDoc().on('mouseup', this.collapseIf, this);
  7160. }, this, true);
  7161. },
  7162. clearSearchHistory : function() {
  7163. this.lastSelectedIndex = 0;
  7164. this.lastSearchTerm = false;
  7165. },
  7166. selectFirst : function() {
  7167. this.focusAndSelect(this.store.data.first());
  7168. },
  7169. selectLast : function() {
  7170. this.focusAndSelect(this.store.data.last());
  7171. },
  7172. selectPrevPage : function() {
  7173. if( !this.rowHeight ) {
  7174. return;
  7175. }
  7176. var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);
  7177. this.focusAndSelect(this.store.getAt(index));
  7178. },
  7179. selectNextPage : function() {
  7180. if( !this.rowHeight ) {
  7181. return;
  7182. }
  7183. var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);
  7184. this.focusAndSelect(this.store.getAt(index));
  7185. },
  7186. search : function(field, value, startIndex) {
  7187. field = field || this.displayField;
  7188. this.lastSearchTerm = value;
  7189. var index = this.store.find.apply(this.store, arguments);
  7190. if( index !== -1 ) {
  7191. this.focusAndSelect(index);
  7192. }
  7193. },
  7194. focusAndSelect : function(record) {
  7195. var index = Ext.isNumber(record) ? record : this.store.indexOf(record);
  7196. this.select(index, this.isExpanded());
  7197. this.onSelect(this.store.getAt(index), index, this.isExpanded());
  7198. },
  7199. calcRowsPerPage : function() {
  7200. if( this.store.getCount() ) {
  7201. this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();
  7202. this.rowsPerPage = this.maxHeight / this.rowHeight;
  7203. } else {
  7204. this.rowHeight = false;
  7205. }
  7206. }
  7207. });
  7208. Ext.reg('selectbox', Ext.ux.form.SelectBox);
  7209. //backwards compat
  7210. Ext.ux.SelectBox = Ext.ux.form.SelectBox;
  7211. /**
  7212. * Plugin for PagingToolbar which replaces the textfield input with a slider
  7213. */
  7214. Ext.ux.SlidingPager = Ext.extend(Object, {
  7215. init : function(pbar){
  7216. var idx = pbar.items.indexOf(pbar.inputItem);
  7217. Ext.each(pbar.items.getRange(idx - 2, idx + 2), function(c){
  7218. c.hide();
  7219. });
  7220. var slider = new Ext.Slider({
  7221. width: 114,
  7222. minValue: 1,
  7223. maxValue: 1,
  7224. plugins: new Ext.slider.Tip({
  7225. getText : function(thumb) {
  7226. return String.format('Page <b>{0}</b> of <b>{1}</b>', thumb.value, thumb.slider.maxValue);
  7227. }
  7228. }),
  7229. listeners: {
  7230. changecomplete: function(s, v){
  7231. pbar.changePage(v);
  7232. }
  7233. }
  7234. });
  7235. pbar.insert(idx + 1, slider);
  7236. pbar.on({
  7237. change: function(pb, data){
  7238. slider.setMaxValue(data.pages);
  7239. slider.setValue(data.activePage);
  7240. }
  7241. });
  7242. }
  7243. });Ext.ns('Ext.ux.form');
  7244. /**
  7245. * @class Ext.ux.form.SpinnerField
  7246. * @extends Ext.form.NumberField
  7247. * Creates a field utilizing Ext.ux.Spinner
  7248. * @xtype spinnerfield
  7249. */
  7250. Ext.ux.form.SpinnerField = Ext.extend(Ext.form.NumberField, {
  7251. actionMode: 'wrap',
  7252. deferHeight: true,
  7253. autoSize: Ext.emptyFn,
  7254. onBlur: Ext.emptyFn,
  7255. adjustSize: Ext.BoxComponent.prototype.adjustSize,
  7256. constructor: function(config) {
  7257. var spinnerConfig = Ext.copyTo({}, config, 'incrementValue,alternateIncrementValue,accelerate,defaultValue,triggerClass,splitterClass');
  7258. var spl = this.spinner = new Ext.ux.Spinner(spinnerConfig);
  7259. var plugins = config.plugins
  7260. ? (Ext.isArray(config.plugins)
  7261. ? config.plugins.push(spl)
  7262. : [config.plugins, spl])
  7263. : spl;
  7264. Ext.ux.form.SpinnerField.superclass.constructor.call(this, Ext.apply(config, {plugins: plugins}));
  7265. },
  7266. // private
  7267. getResizeEl: function(){
  7268. return this.wrap;
  7269. },
  7270. // private
  7271. getPositionEl: function(){
  7272. return this.wrap;
  7273. },
  7274. // private
  7275. alignErrorIcon: function(){
  7276. if (this.wrap) {
  7277. this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
  7278. }
  7279. },
  7280. validateBlur: function(){
  7281. return true;
  7282. }
  7283. });
  7284. Ext.reg('spinnerfield', Ext.ux.form.SpinnerField);
  7285. //backwards compat
  7286. Ext.form.SpinnerField = Ext.ux.form.SpinnerField;
  7287. /**
  7288. * @class Ext.ux.Spinner
  7289. * @extends Ext.util.Observable
  7290. * Creates a Spinner control utilized by Ext.ux.form.SpinnerField
  7291. */
  7292. Ext.ux.Spinner = Ext.extend(Ext.util.Observable, {
  7293. incrementValue: 1,
  7294. alternateIncrementValue: 5,
  7295. triggerClass: 'x-form-spinner-trigger',
  7296. splitterClass: 'x-form-spinner-splitter',
  7297. alternateKey: Ext.EventObject.shiftKey,
  7298. defaultValue: 0,
  7299. accelerate: false,
  7300. constructor: function(config){
  7301. Ext.ux.Spinner.superclass.constructor.call(this, config);
  7302. Ext.apply(this, config);
  7303. this.mimicing = false;
  7304. },
  7305. init: function(field){
  7306. this.field = field;
  7307. field.afterMethod('onRender', this.doRender, this);
  7308. field.afterMethod('onEnable', this.doEnable, this);
  7309. field.afterMethod('onDisable', this.doDisable, this);
  7310. field.afterMethod('afterRender', this.doAfterRender, this);
  7311. field.afterMethod('onResize', this.doResize, this);
  7312. field.afterMethod('onFocus', this.doFocus, this);
  7313. field.beforeMethod('onDestroy', this.doDestroy, this);
  7314. },
  7315. doRender: function(ct, position){
  7316. var el = this.el = this.field.getEl();
  7317. var f = this.field;
  7318. if (!f.wrap) {
  7319. f.wrap = this.wrap = el.wrap({
  7320. cls: "x-form-field-wrap"
  7321. });
  7322. }
  7323. else {
  7324. this.wrap = f.wrap.addClass('x-form-field-wrap');
  7325. }
  7326. this.trigger = this.wrap.createChild({
  7327. tag: "img",
  7328. src: Ext.BLANK_IMAGE_URL,
  7329. cls: "x-form-trigger " + this.triggerClass
  7330. });
  7331. if (!f.width) {
  7332. this.wrap.setWidth(el.getWidth() + this.trigger.getWidth());
  7333. }
  7334. this.splitter = this.wrap.createChild({
  7335. tag: 'div',
  7336. cls: this.splitterClass,
  7337. style: 'width:13px; height:2px;'
  7338. });
  7339. this.splitter.setRight((Ext.isIE) ? 1 : 2).setTop(10).show();
  7340. this.proxy = this.trigger.createProxy('', this.splitter, true);
  7341. this.proxy.addClass("x-form-spinner-proxy");
  7342. this.proxy.setStyle('left', '0px');
  7343. this.proxy.setSize(14, 1);
  7344. this.proxy.hide();
  7345. this.dd = new Ext.dd.DDProxy(this.splitter.dom.id, "SpinnerDrag", {
  7346. dragElId: this.proxy.id
  7347. });
  7348. this.initTrigger();
  7349. this.initSpinner();
  7350. },
  7351. doAfterRender: function(){
  7352. var y;
  7353. if (Ext.isIE && this.el.getY() != (y = this.trigger.getY())) {
  7354. this.el.position();
  7355. this.el.setY(y);
  7356. }
  7357. },
  7358. doEnable: function(){
  7359. if (this.wrap) {
  7360. this.disabled = false;
  7361. this.wrap.removeClass(this.field.disabledClass);
  7362. }
  7363. },
  7364. doDisable: function(){
  7365. if (this.wrap) {
  7366. this.disabled = true;
  7367. this.wrap.addClass(this.field.disabledClass);
  7368. this.el.removeClass(this.field.disabledClass);
  7369. }
  7370. },
  7371. doResize: function(w, h){
  7372. if (typeof w == 'number') {
  7373. this.el.setWidth(w - this.trigger.getWidth());
  7374. }
  7375. this.wrap.setWidth(this.el.getWidth() + this.trigger.getWidth());
  7376. },
  7377. doFocus: function(){
  7378. if (!this.mimicing) {
  7379. this.wrap.addClass('x-trigger-wrap-focus');
  7380. this.mimicing = true;
  7381. Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {
  7382. delay: 10
  7383. });
  7384. this.el.on('keydown', this.checkTab, this);
  7385. }
  7386. },
  7387. // private
  7388. checkTab: function(e){
  7389. if (e.getKey() == e.TAB) {
  7390. this.triggerBlur();
  7391. }
  7392. },
  7393. // private
  7394. mimicBlur: function(e){
  7395. if (!this.wrap.contains(e.target) && this.field.validateBlur(e)) {
  7396. this.triggerBlur();
  7397. }
  7398. },
  7399. // private
  7400. triggerBlur: function(){
  7401. this.mimicing = false;
  7402. Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
  7403. this.el.un("keydown", this.checkTab, this);
  7404. this.field.beforeBlur();
  7405. this.wrap.removeClass('x-trigger-wrap-focus');
  7406. this.field.onBlur.call(this.field);
  7407. },
  7408. initTrigger: function(){
  7409. this.trigger.addClassOnOver('x-form-trigger-over');
  7410. this.trigger.addClassOnClick('x-form-trigger-click');
  7411. },
  7412. initSpinner: function(){
  7413. this.field.addEvents({
  7414. 'spin': true,
  7415. 'spinup': true,
  7416. 'spindown': true
  7417. });
  7418. this.keyNav = new Ext.KeyNav(this.el, {
  7419. "up": function(e){
  7420. e.preventDefault();
  7421. this.onSpinUp();
  7422. },
  7423. "down": function(e){
  7424. e.preventDefault();
  7425. this.onSpinDown();
  7426. },
  7427. "pageUp": function(e){
  7428. e.preventDefault();
  7429. this.onSpinUpAlternate();
  7430. },
  7431. "pageDown": function(e){
  7432. e.preventDefault();
  7433. this.onSpinDownAlternate();
  7434. },
  7435. scope: this
  7436. });
  7437. this.repeater = new Ext.util.ClickRepeater(this.trigger, {
  7438. accelerate: this.accelerate
  7439. });
  7440. this.field.mon(this.repeater, "click", this.onTriggerClick, this, {
  7441. preventDefault: true
  7442. });
  7443. this.field.mon(this.trigger, {
  7444. mouseover: this.onMouseOver,
  7445. mouseout: this.onMouseOut,
  7446. mousemove: this.onMouseMove,
  7447. mousedown: this.onMouseDown,
  7448. mouseup: this.onMouseUp,
  7449. scope: this,
  7450. preventDefault: true
  7451. });
  7452. this.field.mon(this.wrap, "mousewheel", this.handleMouseWheel, this);
  7453. this.dd.setXConstraint(0, 0, 10)
  7454. this.dd.setYConstraint(1500, 1500, 10);
  7455. this.dd.endDrag = this.endDrag.createDelegate(this);
  7456. this.dd.startDrag = this.startDrag.createDelegate(this);
  7457. this.dd.onDrag = this.onDrag.createDelegate(this);
  7458. },
  7459. onMouseOver: function(){
  7460. if (this.disabled) {
  7461. return;
  7462. }
  7463. var middle = this.getMiddle();
  7464. this.tmpHoverClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-overup' : 'x-form-spinner-overdown';
  7465. this.trigger.addClass(this.tmpHoverClass);
  7466. },
  7467. //private
  7468. onMouseOut: function(){
  7469. this.trigger.removeClass(this.tmpHoverClass);
  7470. },
  7471. //private
  7472. onMouseMove: function(){
  7473. if (this.disabled) {
  7474. return;
  7475. }
  7476. var middle = this.getMiddle();
  7477. if (((Ext.EventObject.getPageY() > middle) && this.tmpHoverClass == "x-form-spinner-overup") ||
  7478. ((Ext.EventObject.getPageY() < middle) && this.tmpHoverClass == "x-form-spinner-overdown")) {
  7479. }
  7480. },
  7481. //private
  7482. onMouseDown: function(){
  7483. if (this.disabled) {
  7484. return;
  7485. }
  7486. var middle = this.getMiddle();
  7487. this.tmpClickClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-clickup' : 'x-form-spinner-clickdown';
  7488. this.trigger.addClass(this.tmpClickClass);
  7489. },
  7490. //private
  7491. onMouseUp: function(){
  7492. this.trigger.removeClass(this.tmpClickClass);
  7493. },
  7494. //private
  7495. onTriggerClick: function(){
  7496. if (this.disabled || this.el.dom.readOnly) {
  7497. return;
  7498. }
  7499. var middle = this.getMiddle();
  7500. var ud = (Ext.EventObject.getPageY() < middle) ? 'Up' : 'Down';
  7501. this['onSpin' + ud]();
  7502. },
  7503. //private
  7504. getMiddle: function(){
  7505. var t = this.trigger.getTop();
  7506. var h = this.trigger.getHeight();
  7507. var middle = t + (h / 2);
  7508. return middle;
  7509. },
  7510. //private
  7511. //checks if control is allowed to spin
  7512. isSpinnable: function(){
  7513. if (this.disabled || this.el.dom.readOnly) {
  7514. Ext.EventObject.preventDefault(); //prevent scrolling when disabled/readonly
  7515. return false;
  7516. }
  7517. return true;
  7518. },
  7519. handleMouseWheel: function(e){
  7520. //disable scrolling when not focused
  7521. if (this.wrap.hasClass('x-trigger-wrap-focus') == false) {
  7522. return;
  7523. }
  7524. var delta = e.getWheelDelta();
  7525. if (delta > 0) {
  7526. this.onSpinUp();
  7527. e.stopEvent();
  7528. }
  7529. else
  7530. if (delta < 0) {
  7531. this.onSpinDown();
  7532. e.stopEvent();
  7533. }
  7534. },
  7535. //private
  7536. startDrag: function(){
  7537. this.proxy.show();
  7538. this._previousY = Ext.fly(this.dd.getDragEl()).getTop();
  7539. },
  7540. //private
  7541. endDrag: function(){
  7542. this.proxy.hide();
  7543. },
  7544. //private
  7545. onDrag: function(){
  7546. if (this.disabled) {
  7547. return;
  7548. }
  7549. var y = Ext.fly(this.dd.getDragEl()).getTop();
  7550. var ud = '';
  7551. if (this._previousY > y) {
  7552. ud = 'Up';
  7553. } //up
  7554. if (this._previousY < y) {
  7555. ud = 'Down';
  7556. } //down
  7557. if (ud != '') {
  7558. this['onSpin' + ud]();
  7559. }
  7560. this._previousY = y;
  7561. },
  7562. //private
  7563. onSpinUp: function(){
  7564. if (this.isSpinnable() == false) {
  7565. return;
  7566. }
  7567. if (Ext.EventObject.shiftKey == true) {
  7568. this.onSpinUpAlternate();
  7569. return;
  7570. }
  7571. else {
  7572. this.spin(false, false);
  7573. }
  7574. this.field.fireEvent("spin", this);
  7575. this.field.fireEvent("spinup", this);
  7576. },
  7577. //private
  7578. onSpinDown: function(){
  7579. if (this.isSpinnable() == false) {
  7580. return;
  7581. }
  7582. if (Ext.EventObject.shiftKey == true) {
  7583. this.onSpinDownAlternate();
  7584. return;
  7585. }
  7586. else {
  7587. this.spin(true, false);
  7588. }
  7589. this.field.fireEvent("spin", this);
  7590. this.field.fireEvent("spindown", this);
  7591. },
  7592. //private
  7593. onSpinUpAlternate: function(){
  7594. if (this.isSpinnable() == false) {
  7595. return;
  7596. }
  7597. this.spin(false, true);
  7598. this.field.fireEvent("spin", this);
  7599. this.field.fireEvent("spinup", this);
  7600. },
  7601. //private
  7602. onSpinDownAlternate: function(){
  7603. if (this.isSpinnable() == false) {
  7604. return;
  7605. }
  7606. this.spin(true, true);
  7607. this.field.fireEvent("spin", this);
  7608. this.field.fireEvent("spindown", this);
  7609. },
  7610. spin: function(down, alternate){
  7611. var v = parseFloat(this.field.getValue());
  7612. var incr = (alternate == true) ? this.alternateIncrementValue : this.incrementValue;
  7613. (down == true) ? v -= incr : v += incr;
  7614. v = (isNaN(v)) ? this.defaultValue : v;
  7615. v = this.fixBoundries(v);
  7616. this.field.setRawValue(v);
  7617. },
  7618. fixBoundries: function(value){
  7619. var v = value;
  7620. if (this.field.minValue != undefined && v < this.field.minValue) {
  7621. v = this.field.minValue;
  7622. }
  7623. if (this.field.maxValue != undefined && v > this.field.maxValue) {
  7624. v = this.field.maxValue;
  7625. }
  7626. return this.fixPrecision(v);
  7627. },
  7628. // private
  7629. fixPrecision: function(value){
  7630. var nan = isNaN(value);
  7631. if (!this.field.allowDecimals || this.field.decimalPrecision == -1 || nan || !value) {
  7632. return nan ? '' : value;
  7633. }
  7634. return parseFloat(parseFloat(value).toFixed(this.field.decimalPrecision));
  7635. },
  7636. doDestroy: function(){
  7637. if (this.trigger) {
  7638. this.trigger.remove();
  7639. }
  7640. if (this.wrap) {
  7641. this.wrap.remove();
  7642. delete this.field.wrap;
  7643. }
  7644. if (this.splitter) {
  7645. this.splitter.remove();
  7646. }
  7647. if (this.dd) {
  7648. this.dd.unreg();
  7649. this.dd = null;
  7650. }
  7651. if (this.proxy) {
  7652. this.proxy.remove();
  7653. }
  7654. if (this.repeater) {
  7655. this.repeater.purgeListeners();
  7656. }
  7657. if (this.mimicing){
  7658. Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
  7659. }
  7660. }
  7661. });
  7662. //backwards compat
  7663. Ext.form.Spinner = Ext.ux.Spinner;Ext.ux.Spotlight = function(config){
  7664. Ext.apply(this, config);
  7665. }
  7666. Ext.ux.Spotlight.prototype = {
  7667. active : false,
  7668. animate : true,
  7669. duration: .25,
  7670. easing:'easeNone',
  7671. // private
  7672. animated : false,
  7673. createElements : function(){
  7674. var bd = Ext.getBody();
  7675. this.right = bd.createChild({cls:'x-spotlight'});
  7676. this.left = bd.createChild({cls:'x-spotlight'});
  7677. this.top = bd.createChild({cls:'x-spotlight'});
  7678. this.bottom = bd.createChild({cls:'x-spotlight'});
  7679. this.all = new Ext.CompositeElement([this.right, this.left, this.top, this.bottom]);
  7680. },
  7681. show : function(el, callback, scope){
  7682. if(this.animated){
  7683. this.show.defer(50, this, [el, callback, scope]);
  7684. return;
  7685. }
  7686. this.el = Ext.get(el);
  7687. if(!this.right){
  7688. this.createElements();
  7689. }
  7690. if(!this.active){
  7691. this.all.setDisplayed('');
  7692. this.applyBounds(true, false);
  7693. this.active = true;
  7694. Ext.EventManager.onWindowResize(this.syncSize, this);
  7695. this.applyBounds(false, this.animate, false, callback, scope);
  7696. }else{
  7697. this.applyBounds(false, false, false, callback, scope); // all these booleans look hideous
  7698. }
  7699. },
  7700. hide : function(callback, scope){
  7701. if(this.animated){
  7702. this.hide.defer(50, this, [callback, scope]);
  7703. return;
  7704. }
  7705. Ext.EventManager.removeResizeListener(this.syncSize, this);
  7706. this.applyBounds(true, this.animate, true, callback, scope);
  7707. },
  7708. doHide : function(){
  7709. this.active = false;
  7710. this.all.setDisplayed(false);
  7711. },
  7712. syncSize : function(){
  7713. this.applyBounds(false, false);
  7714. },
  7715. applyBounds : function(basePts, anim, doHide, callback, scope){
  7716. var rg = this.el.getRegion();
  7717. var dw = Ext.lib.Dom.getViewWidth(true);
  7718. var dh = Ext.lib.Dom.getViewHeight(true);
  7719. var c = 0, cb = false;
  7720. if(anim){
  7721. cb = {
  7722. callback: function(){
  7723. c++;
  7724. if(c == 4){
  7725. this.animated = false;
  7726. if(doHide){
  7727. this.doHide();
  7728. }
  7729. Ext.callback(callback, scope, [this]);
  7730. }
  7731. },
  7732. scope: this,
  7733. duration: this.duration,
  7734. easing: this.easing
  7735. };
  7736. this.animated = true;
  7737. }
  7738. this.right.setBounds(
  7739. rg.right,
  7740. basePts ? dh : rg.top,
  7741. dw - rg.right,
  7742. basePts ? 0 : (dh - rg.top),
  7743. cb);
  7744. this.left.setBounds(
  7745. 0,
  7746. 0,
  7747. rg.left,
  7748. basePts ? 0 : rg.bottom,
  7749. cb);
  7750. this.top.setBounds(
  7751. basePts ? dw : rg.left,
  7752. 0,
  7753. basePts ? 0 : dw - rg.left,
  7754. rg.top,
  7755. cb);
  7756. this.bottom.setBounds(
  7757. 0,
  7758. rg.bottom,
  7759. basePts ? 0 : rg.right,
  7760. dh - rg.bottom,
  7761. cb);
  7762. if(!anim){
  7763. if(doHide){
  7764. this.doHide();
  7765. }
  7766. if(callback){
  7767. Ext.callback(callback, scope, [this]);
  7768. }
  7769. }
  7770. },
  7771. destroy : function(){
  7772. this.doHide();
  7773. Ext.destroy(
  7774. this.right,
  7775. this.left,
  7776. this.top,
  7777. this.bottom);
  7778. delete this.el;
  7779. delete this.all;
  7780. }
  7781. };
  7782. //backwards compat
  7783. Ext.Spotlight = Ext.ux.Spotlight;/**
  7784. * @class Ext.ux.StatusBar
  7785. * <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}. In addition to
  7786. * supporting the standard {@link Ext.Toolbar} interface for adding buttons, menus and other items, the StatusBar
  7787. * provides a greedy status element that can be aligned to either side and has convenient methods for setting the
  7788. * status text and icon. You can also indicate that something is processing using the {@link #showBusy} method.</p>
  7789. * <pre><code>
  7790. new Ext.Panel({
  7791. title: 'StatusBar',
  7792. // etc.
  7793. bbar: new Ext.ux.StatusBar({
  7794. id: 'my-status',
  7795. // defaults to use when the status is cleared:
  7796. defaultText: 'Default status text',
  7797. defaultIconCls: 'default-icon',
  7798. // values to set initially:
  7799. text: 'Ready',
  7800. iconCls: 'ready-icon',
  7801. // any standard Toolbar items:
  7802. items: [{
  7803. text: 'A Button'
  7804. }, '-', 'Plain Text']
  7805. })
  7806. });
  7807. // Update the status bar later in code:
  7808. var sb = Ext.getCmp('my-status');
  7809. sb.setStatus({
  7810. text: 'OK',
  7811. iconCls: 'ok-icon',
  7812. clear: true // auto-clear after a set interval
  7813. });
  7814. // Set the status bar to show that something is processing:
  7815. sb.showBusy();
  7816. // processing....
  7817. sb.clearStatus(); // once completeed
  7818. </code></pre>
  7819. * @extends Ext.Toolbar
  7820. * @constructor
  7821. * Creates a new StatusBar
  7822. * @param {Object/Array} config A config object
  7823. */
  7824. Ext.ux.StatusBar = Ext.extend(Ext.Toolbar, {
  7825. /**
  7826. * @cfg {String} statusAlign
  7827. * The alignment of the status element within the overall StatusBar layout. When the StatusBar is rendered,
  7828. * it creates an internal div containing the status text and icon. Any additional Toolbar items added in the
  7829. * StatusBar's {@link #items} config, or added via {@link #add} or any of the supported add* methods, will be
  7830. * rendered, in added order, to the opposite side. The status element is greedy, so it will automatically
  7831. * expand to take up all sapce left over by any other items. Example usage:
  7832. * <pre><code>
  7833. // Create a left-aligned status bar containing a button,
  7834. // separator and text item that will be right-aligned (default):
  7835. new Ext.Panel({
  7836. title: 'StatusBar',
  7837. // etc.
  7838. bbar: new Ext.ux.StatusBar({
  7839. defaultText: 'Default status text',
  7840. id: 'status-id',
  7841. items: [{
  7842. text: 'A Button'
  7843. }, '-', 'Plain Text']
  7844. })
  7845. });
  7846. // By adding the statusAlign config, this will create the
  7847. // exact same toolbar, except the status and toolbar item
  7848. // layout will be reversed from the previous example:
  7849. new Ext.Panel({
  7850. title: 'StatusBar',
  7851. // etc.
  7852. bbar: new Ext.ux.StatusBar({
  7853. defaultText: 'Default status text',
  7854. id: 'status-id',
  7855. statusAlign: 'right',
  7856. items: [{
  7857. text: 'A Button'
  7858. }, '-', 'Plain Text']
  7859. })
  7860. });
  7861. </code></pre>
  7862. */
  7863. /**
  7864. * @cfg {String} defaultText
  7865. * The default {@link #text} value. This will be used anytime the status bar is cleared with the
  7866. * <tt>useDefaults:true</tt> option (defaults to '').
  7867. */
  7868. /**
  7869. * @cfg {String} defaultIconCls
  7870. * The default {@link #iconCls} value (see the iconCls docs for additional details about customizing the icon).
  7871. * This will be used anytime the status bar is cleared with the <tt>useDefaults:true</tt> option (defaults to '').
  7872. */
  7873. /**
  7874. * @cfg {String} text
  7875. * A string that will be <b>initially</b> set as the status message. This string
  7876. * will be set as innerHTML (html tags are accepted) for the toolbar item.
  7877. * If not specified, the value set for <code>{@link #defaultText}</code>
  7878. * will be used.
  7879. */
  7880. /**
  7881. * @cfg {String} iconCls
  7882. * A CSS class that will be <b>initially</b> set as the status bar icon and is
  7883. * expected to provide a background image (defaults to '').
  7884. * Example usage:<pre><code>
  7885. // Example CSS rule:
  7886. .x-statusbar .x-status-custom {
  7887. padding-left: 25px;
  7888. background: transparent url(images/custom-icon.gif) no-repeat 3px 2px;
  7889. }
  7890. // Setting a default icon:
  7891. var sb = new Ext.ux.StatusBar({
  7892. defaultIconCls: 'x-status-custom'
  7893. });
  7894. // Changing the icon:
  7895. sb.setStatus({
  7896. text: 'New status',
  7897. iconCls: 'x-status-custom'
  7898. });
  7899. </code></pre>
  7900. */
  7901. /**
  7902. * @cfg {String} cls
  7903. * The base class applied to the containing element for this component on render (defaults to 'x-statusbar')
  7904. */
  7905. cls : 'x-statusbar',
  7906. /**
  7907. * @cfg {String} busyIconCls
  7908. * The default <code>{@link #iconCls}</code> applied when calling
  7909. * <code>{@link #showBusy}</code> (defaults to <tt>'x-status-busy'</tt>).
  7910. * It can be overridden at any time by passing the <code>iconCls</code>
  7911. * argument into <code>{@link #showBusy}</code>.
  7912. */
  7913. busyIconCls : 'x-status-busy',
  7914. /**
  7915. * @cfg {String} busyText
  7916. * The default <code>{@link #text}</code> applied when calling
  7917. * <code>{@link #showBusy}</code> (defaults to <tt>'Loading...'</tt>).
  7918. * It can be overridden at any time by passing the <code>text</code>
  7919. * argument into <code>{@link #showBusy}</code>.
  7920. */
  7921. busyText : 'Loading...',
  7922. /**
  7923. * @cfg {Number} autoClear
  7924. * The number of milliseconds to wait after setting the status via
  7925. * <code>{@link #setStatus}</code> before automatically clearing the status
  7926. * text and icon (defaults to <tt>5000</tt>). Note that this only applies
  7927. * when passing the <tt>clear</tt> argument to <code>{@link #setStatus}</code>
  7928. * since that is the only way to defer clearing the status. This can
  7929. * be overridden by specifying a different <tt>wait</tt> value in
  7930. * <code>{@link #setStatus}</code>. Calls to <code>{@link #clearStatus}</code>
  7931. * always clear the status bar immediately and ignore this value.
  7932. */
  7933. autoClear : 5000,
  7934. /**
  7935. * @cfg {String} emptyText
  7936. * The text string to use if no text has been set. Defaults to
  7937. * <tt>'&nbsp;'</tt>). If there are no other items in the toolbar using
  7938. * an empty string (<tt>''</tt>) for this value would end up in the toolbar
  7939. * height collapsing since the empty string will not maintain the toolbar
  7940. * height. Use <tt>''</tt> if the toolbar should collapse in height
  7941. * vertically when no text is specified and there are no other items in
  7942. * the toolbar.
  7943. */
  7944. emptyText : '&nbsp;',
  7945. // private
  7946. activeThreadId : 0,
  7947. // private
  7948. initComponent : function(){
  7949. if(this.statusAlign=='right'){
  7950. this.cls += ' x-status-right';
  7951. }
  7952. Ext.ux.StatusBar.superclass.initComponent.call(this);
  7953. },
  7954. // private
  7955. afterRender : function(){
  7956. Ext.ux.StatusBar.superclass.afterRender.call(this);
  7957. var right = this.statusAlign == 'right';
  7958. this.currIconCls = this.iconCls || this.defaultIconCls;
  7959. this.statusEl = new Ext.Toolbar.TextItem({
  7960. cls: 'x-status-text ' + (this.currIconCls || ''),
  7961. text: this.text || this.defaultText || ''
  7962. });
  7963. if(right){
  7964. this.add('->');
  7965. this.add(this.statusEl);
  7966. }else{
  7967. this.insert(0, this.statusEl);
  7968. this.insert(1, '->');
  7969. }
  7970. this.doLayout();
  7971. },
  7972. /**
  7973. * Sets the status {@link #text} and/or {@link #iconCls}. Also supports automatically clearing the
  7974. * status that was set after a specified interval.
  7975. * @param {Object/String} config A config object specifying what status to set, or a string assumed
  7976. * to be the status text (and all other options are defaulted as explained below). A config
  7977. * object containing any or all of the following properties can be passed:<ul>
  7978. * <li><tt>text</tt> {String} : (optional) The status text to display. If not specified, any current
  7979. * status text will remain unchanged.</li>
  7980. * <li><tt>iconCls</tt> {String} : (optional) The CSS class used to customize the status icon (see
  7981. * {@link #iconCls} for details). If not specified, any current iconCls will remain unchanged.</li>
  7982. * <li><tt>clear</tt> {Boolean/Number/Object} : (optional) Allows you to set an internal callback that will
  7983. * automatically clear the status text and iconCls after a specified amount of time has passed. If clear is not
  7984. * specified, the new status will not be auto-cleared and will stay until updated again or cleared using
  7985. * {@link #clearStatus}. If <tt>true</tt> is passed, the status will be cleared using {@link #autoClear},
  7986. * {@link #defaultText} and {@link #defaultIconCls} via a fade out animation. If a numeric value is passed,
  7987. * it will be used as the callback interval (in milliseconds), overriding the {@link #autoClear} value.
  7988. * All other options will be defaulted as with the boolean option. To customize any other options,
  7989. * you can pass an object in the format:<ul>
  7990. * <li><tt>wait</tt> {Number} : (optional) The number of milliseconds to wait before clearing
  7991. * (defaults to {@link #autoClear}).</li>
  7992. * <li><tt>anim</tt> {Number} : (optional) False to clear the status immediately once the callback
  7993. * executes (defaults to true which fades the status out).</li>
  7994. * <li><tt>useDefaults</tt> {Number} : (optional) False to completely clear the status text and iconCls
  7995. * (defaults to true which uses {@link #defaultText} and {@link #defaultIconCls}).</li>
  7996. * </ul></li></ul>
  7997. * Example usage:<pre><code>
  7998. // Simple call to update the text
  7999. statusBar.setStatus('New status');
  8000. // Set the status and icon, auto-clearing with default options:
  8001. statusBar.setStatus({
  8002. text: 'New status',
  8003. iconCls: 'x-status-custom',
  8004. clear: true
  8005. });
  8006. // Auto-clear with custom options:
  8007. statusBar.setStatus({
  8008. text: 'New status',
  8009. iconCls: 'x-status-custom',
  8010. clear: {
  8011. wait: 8000,
  8012. anim: false,
  8013. useDefaults: false
  8014. }
  8015. });
  8016. </code></pre>
  8017. * @return {Ext.ux.StatusBar} this
  8018. */
  8019. setStatus : function(o){
  8020. o = o || {};
  8021. if(typeof o == 'string'){
  8022. o = {text:o};
  8023. }
  8024. if(o.text !== undefined){
  8025. this.setText(o.text);
  8026. }
  8027. if(o.iconCls !== undefined){
  8028. this.setIcon(o.iconCls);
  8029. }
  8030. if(o.clear){
  8031. var c = o.clear,
  8032. wait = this.autoClear,
  8033. defaults = {useDefaults: true, anim: true};
  8034. if(typeof c == 'object'){
  8035. c = Ext.applyIf(c, defaults);
  8036. if(c.wait){
  8037. wait = c.wait;
  8038. }
  8039. }else if(typeof c == 'number'){
  8040. wait = c;
  8041. c = defaults;
  8042. }else if(typeof c == 'boolean'){
  8043. c = defaults;
  8044. }
  8045. c.threadId = this.activeThreadId;
  8046. this.clearStatus.defer(wait, this, [c]);
  8047. }
  8048. return this;
  8049. },
  8050. /**
  8051. * Clears the status {@link #text} and {@link #iconCls}. Also supports clearing via an optional fade out animation.
  8052. * @param {Object} config (optional) A config object containing any or all of the following properties. If this
  8053. * object is not specified the status will be cleared using the defaults below:<ul>
  8054. * <li><tt>anim</tt> {Boolean} : (optional) True to clear the status by fading out the status element (defaults
  8055. * to false which clears immediately).</li>
  8056. * <li><tt>useDefaults</tt> {Boolean} : (optional) True to reset the text and icon using {@link #defaultText} and
  8057. * {@link #defaultIconCls} (defaults to false which sets the text to '' and removes any existing icon class).</li>
  8058. * </ul>
  8059. * @return {Ext.ux.StatusBar} this
  8060. */
  8061. clearStatus : function(o){
  8062. o = o || {};
  8063. if(o.threadId && o.threadId !== this.activeThreadId){
  8064. // this means the current call was made internally, but a newer
  8065. // thread has set a message since this call was deferred. Since
  8066. // we don't want to overwrite a newer message just ignore.
  8067. return this;
  8068. }
  8069. var text = o.useDefaults ? this.defaultText : this.emptyText,
  8070. iconCls = o.useDefaults ? (this.defaultIconCls ? this.defaultIconCls : '') : '';
  8071. if(o.anim){
  8072. // animate the statusEl Ext.Element
  8073. this.statusEl.el.fadeOut({
  8074. remove: false,
  8075. useDisplay: true,
  8076. scope: this,
  8077. callback: function(){
  8078. this.setStatus({
  8079. text: text,
  8080. iconCls: iconCls
  8081. });
  8082. this.statusEl.el.show();
  8083. }
  8084. });
  8085. }else{
  8086. // hide/show the el to avoid jumpy text or icon
  8087. this.statusEl.hide();
  8088. this.setStatus({
  8089. text: text,
  8090. iconCls: iconCls
  8091. });
  8092. this.statusEl.show();
  8093. }
  8094. return this;
  8095. },
  8096. /**
  8097. * Convenience method for setting the status text directly. For more flexible options see {@link #setStatus}.
  8098. * @param {String} text (optional) The text to set (defaults to '')
  8099. * @return {Ext.ux.StatusBar} this
  8100. */
  8101. setText : function(text){
  8102. this.activeThreadId++;
  8103. this.text = text || '';
  8104. if(this.rendered){
  8105. this.statusEl.setText(this.text);
  8106. }
  8107. return this;
  8108. },
  8109. /**
  8110. * Returns the current status text.
  8111. * @return {String} The status text
  8112. */
  8113. getText : function(){
  8114. return this.text;
  8115. },
  8116. /**
  8117. * Convenience method for setting the status icon directly. For more flexible options see {@link #setStatus}.
  8118. * See {@link #iconCls} for complete details about customizing the icon.
  8119. * @param {String} iconCls (optional) The icon class to set (defaults to '', and any current icon class is removed)
  8120. * @return {Ext.ux.StatusBar} this
  8121. */
  8122. setIcon : function(cls){
  8123. this.activeThreadId++;
  8124. cls = cls || '';
  8125. if(this.rendered){
  8126. if(this.currIconCls){
  8127. this.statusEl.removeClass(this.currIconCls);
  8128. this.currIconCls = null;
  8129. }
  8130. if(cls.length > 0){
  8131. this.statusEl.addClass(cls);
  8132. this.currIconCls = cls;
  8133. }
  8134. }else{
  8135. this.currIconCls = cls;
  8136. }
  8137. return this;
  8138. },
  8139. /**
  8140. * Convenience method for setting the status text and icon to special values that are pre-configured to indicate
  8141. * a "busy" state, usually for loading or processing activities.
  8142. * @param {Object/String} config (optional) A config object in the same format supported by {@link #setStatus}, or a
  8143. * string to use as the status text (in which case all other options for setStatus will be defaulted). Use the
  8144. * <tt>text</tt> and/or <tt>iconCls</tt> properties on the config to override the default {@link #busyText}
  8145. * and {@link #busyIconCls} settings. If the config argument is not specified, {@link #busyText} and
  8146. * {@link #busyIconCls} will be used in conjunction with all of the default options for {@link #setStatus}.
  8147. * @return {Ext.ux.StatusBar} this
  8148. */
  8149. showBusy : function(o){
  8150. if(typeof o == 'string'){
  8151. o = {text:o};
  8152. }
  8153. o = Ext.applyIf(o || {}, {
  8154. text: this.busyText,
  8155. iconCls: this.busyIconCls
  8156. });
  8157. return this.setStatus(o);
  8158. }
  8159. });
  8160. Ext.reg('statusbar', Ext.ux.StatusBar);
  8161. /**
  8162. * @class Ext.ux.TabCloseMenu
  8163. * @extends Object
  8164. * Plugin (ptype = 'tabclosemenu') for adding a close context menu to tabs. Note that the menu respects
  8165. * the closable configuration on the tab. As such, commands like remove others and remove all will not
  8166. * remove items that are not closable.
  8167. *
  8168. * @constructor
  8169. * @param {Object} config The configuration options
  8170. * @ptype tabclosemenu
  8171. */
  8172. Ext.ux.TabCloseMenu = Ext.extend(Object, {
  8173. /**
  8174. * @cfg {String} closeTabText
  8175. * The text for closing the current tab. Defaults to <tt>'Close Tab'</tt>.
  8176. */
  8177. closeTabText: 'Close Tab',
  8178. /**
  8179. * @cfg {String} closeOtherTabsText
  8180. * The text for closing all tabs except the current one. Defaults to <tt>'Close Other Tabs'</tt>.
  8181. */
  8182. closeOtherTabsText: 'Close Other Tabs',
  8183. /**
  8184. * @cfg {Boolean} showCloseAll
  8185. * Indicates whether to show the 'Close All' option. Defaults to <tt>true</tt>.
  8186. */
  8187. showCloseAll: true,
  8188. /**
  8189. * @cfg {String} closeAllTabsText
  8190. * <p>The text for closing all tabs. Defaults to <tt>'Close All Tabs'</tt>.
  8191. */
  8192. closeAllTabsText: 'Close All Tabs',
  8193. constructor : function(config){
  8194. Ext.apply(this, config || {});
  8195. },
  8196. //public
  8197. init : function(tabs){
  8198. this.tabs = tabs;
  8199. tabs.on({
  8200. scope: this,
  8201. contextmenu: this.onContextMenu,
  8202. destroy: this.destroy
  8203. });
  8204. },
  8205. destroy : function(){
  8206. Ext.destroy(this.menu);
  8207. delete this.menu;
  8208. delete this.tabs;
  8209. delete this.active;
  8210. },
  8211. // private
  8212. onContextMenu : function(tabs, item, e){
  8213. this.active = item;
  8214. var m = this.createMenu(),
  8215. disableAll = true,
  8216. disableOthers = true,
  8217. closeAll = m.getComponent('closeall');
  8218. m.getComponent('close').setDisabled(!item.closable);
  8219. tabs.items.each(function(){
  8220. if(this.closable){
  8221. disableAll = false;
  8222. if(this != item){
  8223. disableOthers = false;
  8224. return false;
  8225. }
  8226. }
  8227. });
  8228. m.getComponent('closeothers').setDisabled(disableOthers);
  8229. if(closeAll){
  8230. closeAll.setDisabled(disableAll);
  8231. }
  8232. e.stopEvent();
  8233. m.showAt(e.getPoint());
  8234. },
  8235. createMenu : function(){
  8236. if(!this.menu){
  8237. var items = [{
  8238. itemId: 'close',
  8239. text: this.closeTabText,
  8240. scope: this,
  8241. handler: this.onClose
  8242. }];
  8243. if(this.showCloseAll){
  8244. items.push('-');
  8245. }
  8246. items.push({
  8247. itemId: 'closeothers',
  8248. text: this.closeOtherTabsText,
  8249. scope: this,
  8250. handler: this.onCloseOthers
  8251. });
  8252. if(this.showCloseAll){
  8253. items.push({
  8254. itemId: 'closeall',
  8255. text: this.closeAllTabsText,
  8256. scope: this,
  8257. handler: this.onCloseAll
  8258. });
  8259. }
  8260. this.menu = new Ext.menu.Menu({
  8261. items: items
  8262. });
  8263. }
  8264. return this.menu;
  8265. },
  8266. onClose : function(){
  8267. this.tabs.remove(this.active);
  8268. },
  8269. onCloseOthers : function(){
  8270. this.doClose(true);
  8271. },
  8272. onCloseAll : function(){
  8273. this.doClose(false);
  8274. },
  8275. doClose : function(excludeActive){
  8276. var items = [];
  8277. this.tabs.items.each(function(item){
  8278. if(item.closable){
  8279. if(!excludeActive || item != this.active){
  8280. items.push(item);
  8281. }
  8282. }
  8283. }, this);
  8284. Ext.each(items, function(item){
  8285. this.tabs.remove(item);
  8286. }, this);
  8287. }
  8288. });
  8289. Ext.preg('tabclosemenu', Ext.ux.TabCloseMenu);Ext.ns('Ext.ux.grid');
  8290. /**
  8291. * @class Ext.ux.grid.TableGrid
  8292. * @extends Ext.grid.GridPanel
  8293. * A Grid which creates itself from an existing HTML table element.
  8294. * @history
  8295. * 2007-03-01 Original version by Nige "Animal" White
  8296. * 2007-03-10 jvs Slightly refactored to reuse existing classes * @constructor
  8297. * @param {String/HTMLElement/Ext.Element} table The table element from which this grid will be created -
  8298. * The table MUST have some type of size defined for the grid to fill. The container will be
  8299. * automatically set to position relative if it isn't already.
  8300. * @param {Object} config A config object that sets properties on this grid and has two additional (optional)
  8301. * properties: fields and columns which allow for customizing data fields and columns for this grid.
  8302. */
  8303. Ext.ux.grid.TableGrid = function(table, config){
  8304. config = config ||
  8305. {};
  8306. Ext.apply(this, config);
  8307. var cf = config.fields || [], ch = config.columns || [];
  8308. table = Ext.get(table);
  8309. var ct = table.insertSibling();
  8310. var fields = [], cols = [];
  8311. var headers = table.query("thead th");
  8312. for (var i = 0, h; h = headers[i]; i++) {
  8313. var text = h.innerHTML;
  8314. var name = 'tcol-' + i;
  8315. fields.push(Ext.applyIf(cf[i] ||
  8316. {}, {
  8317. name: name,
  8318. mapping: 'td:nth(' + (i + 1) + ')/@innerHTML'
  8319. }));
  8320. cols.push(Ext.applyIf(ch[i] ||
  8321. {}, {
  8322. 'header': text,
  8323. 'dataIndex': name,
  8324. 'width': h.offsetWidth,
  8325. 'tooltip': h.title,
  8326. 'sortable': true
  8327. }));
  8328. }
  8329. var ds = new Ext.data.Store({
  8330. reader: new Ext.data.XmlReader({
  8331. record: 'tbody tr'
  8332. }, fields)
  8333. });
  8334. ds.loadData(table.dom);
  8335. var cm = new Ext.grid.ColumnModel(cols);
  8336. if (config.width || config.height) {
  8337. ct.setSize(config.width || 'auto', config.height || 'auto');
  8338. }
  8339. else {
  8340. ct.setWidth(table.getWidth());
  8341. }
  8342. if (config.remove !== false) {
  8343. table.remove();
  8344. }
  8345. Ext.applyIf(this, {
  8346. 'ds': ds,
  8347. 'cm': cm,
  8348. 'sm': new Ext.grid.RowSelectionModel(),
  8349. autoHeight: true,
  8350. autoWidth: false
  8351. });
  8352. Ext.ux.grid.TableGrid.superclass.constructor.call(this, ct, {});
  8353. };
  8354. Ext.extend(Ext.ux.grid.TableGrid, Ext.grid.GridPanel);
  8355. //backwards compat
  8356. Ext.grid.TableGrid = Ext.ux.grid.TableGrid;
  8357. Ext.ns('Ext.ux');
  8358. /**
  8359. * @class Ext.ux.TabScrollerMenu
  8360. * @extends Object
  8361. * Plugin (ptype = 'tabscrollermenu') for adding a tab scroller menu to tabs.
  8362. * @constructor
  8363. * @param {Object} config Configuration options
  8364. * @ptype tabscrollermenu
  8365. */
  8366. Ext.ux.TabScrollerMenu = Ext.extend(Object, {
  8367. /**
  8368. * @cfg {Number} pageSize How many items to allow per submenu.
  8369. */
  8370. pageSize : 10,
  8371. /**
  8372. * @cfg {Number} maxText How long should the title of each {@link Ext.menu.Item} be.
  8373. */
  8374. maxText : 15,
  8375. /**
  8376. * @cfg {String} menuPrefixText Text to prefix the submenus.
  8377. */
  8378. menuPrefixText : 'Items',
  8379. constructor : function(config) {
  8380. config = config || {};
  8381. Ext.apply(this, config);
  8382. },
  8383. //private
  8384. init : function(tabPanel) {
  8385. Ext.apply(tabPanel, this.parentOverrides);
  8386. tabPanel.tabScrollerMenu = this;
  8387. var thisRef = this;
  8388. tabPanel.on({
  8389. render : {
  8390. scope : tabPanel,
  8391. single : true,
  8392. fn : function() {
  8393. var newFn = tabPanel.createScrollers.createSequence(thisRef.createPanelsMenu, this);
  8394. tabPanel.createScrollers = newFn;
  8395. }
  8396. }
  8397. });
  8398. },
  8399. // private && sequeneced
  8400. createPanelsMenu : function() {
  8401. var h = this.stripWrap.dom.offsetHeight;
  8402. //move the right menu item to the left 18px
  8403. var rtScrBtn = this.header.dom.firstChild;
  8404. Ext.fly(rtScrBtn).applyStyles({
  8405. right : '18px'
  8406. });
  8407. var stripWrap = Ext.get(this.strip.dom.parentNode);
  8408. stripWrap.applyStyles({
  8409. 'margin-right' : '36px'
  8410. });
  8411. // Add the new righthand menu
  8412. var scrollMenu = this.header.insertFirst({
  8413. cls:'x-tab-tabmenu-right'
  8414. });
  8415. scrollMenu.setHeight(h);
  8416. scrollMenu.addClassOnOver('x-tab-tabmenu-over');
  8417. scrollMenu.on('click', this.showTabsMenu, this);
  8418. this.scrollLeft.show = this.scrollLeft.show.createSequence(function() {
  8419. scrollMenu.show();
  8420. });
  8421. this.scrollLeft.hide = this.scrollLeft.hide.createSequence(function() {
  8422. scrollMenu.hide();
  8423. });
  8424. },
  8425. /**
  8426. * Returns an the current page size (this.pageSize);
  8427. * @return {Number} this.pageSize The current page size.
  8428. */
  8429. getPageSize : function() {
  8430. return this.pageSize;
  8431. },
  8432. /**
  8433. * Sets the number of menu items per submenu "page size".
  8434. * @param {Number} pageSize The page size
  8435. */
  8436. setPageSize : function(pageSize) {
  8437. this.pageSize = pageSize;
  8438. },
  8439. /**
  8440. * Returns the current maxText length;
  8441. * @return {Number} this.maxText The current max text length.
  8442. */
  8443. getMaxText : function() {
  8444. return this.maxText;
  8445. },
  8446. /**
  8447. * Sets the maximum text size for each menu item.
  8448. * @param {Number} t The max text per each menu item.
  8449. */
  8450. setMaxText : function(t) {
  8451. this.maxText = t;
  8452. },
  8453. /**
  8454. * Returns the current menu prefix text String.;
  8455. * @return {String} this.menuPrefixText The current menu prefix text.
  8456. */
  8457. getMenuPrefixText : function() {
  8458. return this.menuPrefixText;
  8459. },
  8460. /**
  8461. * Sets the menu prefix text String.
  8462. * @param {String} t The menu prefix text.
  8463. */
  8464. setMenuPrefixText : function(t) {
  8465. this.menuPrefixText = t;
  8466. },
  8467. // private && applied to the tab panel itself.
  8468. parentOverrides : {
  8469. // all execute within the scope of the tab panel
  8470. // private
  8471. showTabsMenu : function(e) {
  8472. if (this.tabsMenu) {
  8473. this.tabsMenu.destroy();
  8474. this.un('destroy', this.tabsMenu.destroy, this.tabsMenu);
  8475. this.tabsMenu = null;
  8476. }
  8477. this.tabsMenu = new Ext.menu.Menu();
  8478. this.on('destroy', this.tabsMenu.destroy, this.tabsMenu);
  8479. this.generateTabMenuItems();
  8480. var target = Ext.get(e.getTarget());
  8481. var xy = target.getXY();
  8482. //
  8483. //Y param + 24 pixels
  8484. xy[1] += 24;
  8485. this.tabsMenu.showAt(xy);
  8486. },
  8487. // private
  8488. generateTabMenuItems : function() {
  8489. var curActive = this.getActiveTab();
  8490. var totalItems = this.items.getCount();
  8491. var pageSize = this.tabScrollerMenu.getPageSize();
  8492. if (totalItems > pageSize) {
  8493. var numSubMenus = Math.floor(totalItems / pageSize);
  8494. var remainder = totalItems % pageSize;
  8495. // Loop through all of the items and create submenus in chunks of 10
  8496. for (var i = 0 ; i < numSubMenus; i++) {
  8497. var curPage = (i + 1) * pageSize;
  8498. var menuItems = [];
  8499. for (var x = 0; x < pageSize; x++) {
  8500. index = x + curPage - pageSize;
  8501. var item = this.items.get(index);
  8502. menuItems.push(this.autoGenMenuItem(item));
  8503. }
  8504. this.tabsMenu.add({
  8505. text : this.tabScrollerMenu.getMenuPrefixText() + ' ' + (curPage - pageSize + 1) + ' - ' + curPage,
  8506. menu : menuItems
  8507. });
  8508. }
  8509. // remaining items
  8510. if (remainder > 0) {
  8511. var start = numSubMenus * pageSize;
  8512. menuItems = [];
  8513. for (var i = start ; i < totalItems; i ++ ) {
  8514. var item = this.items.get(i);
  8515. menuItems.push(this.autoGenMenuItem(item));
  8516. }
  8517. this.tabsMenu.add({
  8518. text : this.tabScrollerMenu.menuPrefixText + ' ' + (start + 1) + ' - ' + (start + menuItems.length),
  8519. menu : menuItems
  8520. });
  8521. }
  8522. }
  8523. else {
  8524. this.items.each(function(item) {
  8525. if (item.id != curActive.id && !item.hidden) {
  8526. this.tabsMenu.add(this.autoGenMenuItem(item));
  8527. }
  8528. }, this);
  8529. }
  8530. },
  8531. // private
  8532. autoGenMenuItem : function(item) {
  8533. var maxText = this.tabScrollerMenu.getMaxText();
  8534. var text = Ext.util.Format.ellipsis(item.title, maxText);
  8535. return {
  8536. text : text,
  8537. handler : this.showTabFromMenu,
  8538. scope : this,
  8539. disabled : item.disabled,
  8540. tabToShow : item,
  8541. iconCls : item.iconCls
  8542. }
  8543. },
  8544. // private
  8545. showTabFromMenu : function(menuItem) {
  8546. this.setActiveTab(menuItem.tabToShow);
  8547. }
  8548. }
  8549. });
  8550. Ext.reg('tabscrollermenu', Ext.ux.TabScrollerMenu);
  8551. Ext.ns('Ext.ux.tree');
  8552. /**
  8553. * @class Ext.ux.tree.XmlTreeLoader
  8554. * @extends Ext.tree.TreeLoader
  8555. * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
  8556. * Any text value included as a text node in the XML will be added to the parent node as an attribute
  8557. * called <tt>innerText</tt>. Also, the tag name of each XML node will be added to the tree node as
  8558. * an attribute called <tt>tagName</tt>.</p>
  8559. * <p>By default, this class expects that your source XML will provide the necessary attributes on each
  8560. * node as expected by the {@link Ext.tree.TreePanel} to display and load properly. However, you can
  8561. * provide your own custom processing of node attributes by overriding the {@link #processNode} method
  8562. * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
  8563. * @constructor
  8564. * Creates a new XmlTreeloader.
  8565. * @param {Object} config A config object containing config properties.
  8566. */
  8567. Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
  8568. /**
  8569. * @property XML_NODE_ELEMENT
  8570. * XML element node (value 1, read-only)
  8571. * @type Number
  8572. */
  8573. XML_NODE_ELEMENT : 1,
  8574. /**
  8575. * @property XML_NODE_TEXT
  8576. * XML text node (value 3, read-only)
  8577. * @type Number
  8578. */
  8579. XML_NODE_TEXT : 3,
  8580. // private override
  8581. processResponse : function(response, node, callback){
  8582. var xmlData = response.responseXML,
  8583. root = xmlData.documentElement || xmlData;
  8584. try{
  8585. node.beginUpdate();
  8586. node.appendChild(this.parseXml(root));
  8587. node.endUpdate();
  8588. this.runCallback(callback, scope || node, [node]);
  8589. }catch(e){
  8590. this.handleFailure(response);
  8591. }
  8592. },
  8593. // private
  8594. parseXml : function(node) {
  8595. var nodes = [];
  8596. Ext.each(node.childNodes, function(n){
  8597. if(n.nodeType == this.XML_NODE_ELEMENT){
  8598. var treeNode = this.createNode(n);
  8599. if(n.childNodes.length > 0){
  8600. var child = this.parseXml(n);
  8601. if(typeof child == 'string'){
  8602. treeNode.attributes.innerText = child;
  8603. }else{
  8604. treeNode.appendChild(child);
  8605. }
  8606. }
  8607. nodes.push(treeNode);
  8608. }
  8609. else if(n.nodeType == this.XML_NODE_TEXT){
  8610. var text = n.nodeValue.trim();
  8611. if(text.length > 0){
  8612. return nodes = text;
  8613. }
  8614. }
  8615. }, this);
  8616. return nodes;
  8617. },
  8618. // private override
  8619. createNode : function(node){
  8620. var attr = {
  8621. tagName: node.tagName
  8622. };
  8623. Ext.each(node.attributes, function(a){
  8624. attr[a.nodeName] = a.nodeValue;
  8625. });
  8626. this.processAttributes(attr);
  8627. return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
  8628. },
  8629. /*
  8630. * Template method intended to be overridden by subclasses that need to provide
  8631. * custom attribute processing prior to the creation of each TreeNode. This method
  8632. * will be passed a config object containing existing TreeNode attribute name/value
  8633. * pairs which can be modified as needed directly (no need to return the object).
  8634. */
  8635. processAttributes: Ext.emptyFn
  8636. });
  8637. //backwards compat
  8638. Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;
  8639. /**
  8640. * @class Ext.ux.ValidationStatus
  8641. * A {@link Ext.StatusBar} plugin that provides automatic error notification when the
  8642. * associated form contains validation errors.
  8643. * @extends Ext.Component
  8644. * @constructor
  8645. * Creates a new ValiationStatus plugin
  8646. * @param {Object} config A config object
  8647. */
  8648. Ext.ux.ValidationStatus = Ext.extend(Ext.Component, {
  8649. /**
  8650. * @cfg {String} errorIconCls
  8651. * The {@link #iconCls} value to be applied to the status message when there is a
  8652. * validation error. Defaults to <tt>'x-status-error'</tt>.
  8653. */
  8654. errorIconCls : 'x-status-error',
  8655. /**
  8656. * @cfg {String} errorListCls
  8657. * The css class to be used for the error list when there are validation errors.
  8658. * Defaults to <tt>'x-status-error-list'</tt>.
  8659. */
  8660. errorListCls : 'x-status-error-list',
  8661. /**
  8662. * @cfg {String} validIconCls
  8663. * The {@link #iconCls} value to be applied to the status message when the form
  8664. * validates. Defaults to <tt>'x-status-valid'</tt>.
  8665. */
  8666. validIconCls : 'x-status-valid',
  8667. /**
  8668. * @cfg {String} showText
  8669. * The {@link #text} value to be applied when there is a form validation error.
  8670. * Defaults to <tt>'The form has errors (click for details...)'</tt>.
  8671. */
  8672. showText : 'The form has errors (click for details...)',
  8673. /**
  8674. * @cfg {String} showText
  8675. * The {@link #text} value to display when the error list is displayed.
  8676. * Defaults to <tt>'Click again to hide the error list'</tt>.
  8677. */
  8678. hideText : 'Click again to hide the error list',
  8679. /**
  8680. * @cfg {String} submitText
  8681. * The {@link #text} value to be applied when the form is being submitted.
  8682. * Defaults to <tt>'Saving...'</tt>.
  8683. */
  8684. submitText : 'Saving...',
  8685. // private
  8686. init : function(sb){
  8687. sb.on('render', function(){
  8688. this.statusBar = sb;
  8689. this.monitor = true;
  8690. this.errors = new Ext.util.MixedCollection();
  8691. this.listAlign = (sb.statusAlign=='right' ? 'br-tr?' : 'bl-tl?');
  8692. if(this.form){
  8693. this.form = Ext.getCmp(this.form).getForm();
  8694. this.startMonitoring();
  8695. this.form.on('beforeaction', function(f, action){
  8696. if(action.type == 'submit'){
  8697. // Ignore monitoring while submitting otherwise the field validation
  8698. // events cause the status message to reset too early
  8699. this.monitor = false;
  8700. }
  8701. }, this);
  8702. var startMonitor = function(){
  8703. this.monitor = true;
  8704. };
  8705. this.form.on('actioncomplete', startMonitor, this);
  8706. this.form.on('actionfailed', startMonitor, this);
  8707. }
  8708. }, this, {single:true});
  8709. sb.on({
  8710. scope: this,
  8711. afterlayout:{
  8712. single: true,
  8713. fn: function(){
  8714. // Grab the statusEl after the first layout.
  8715. sb.statusEl.getEl().on('click', this.onStatusClick, this, {buffer:200});
  8716. }
  8717. },
  8718. beforedestroy:{
  8719. single: true,
  8720. fn: this.onDestroy
  8721. }
  8722. });
  8723. },
  8724. // private
  8725. startMonitoring : function(){
  8726. this.form.items.each(function(f){
  8727. f.on('invalid', this.onFieldValidation, this);
  8728. f.on('valid', this.onFieldValidation, this);
  8729. }, this);
  8730. },
  8731. // private
  8732. stopMonitoring : function(){
  8733. this.form.items.each(function(f){
  8734. f.un('invalid', this.onFieldValidation, this);
  8735. f.un('valid', this.onFieldValidation, this);
  8736. }, this);
  8737. },
  8738. // private
  8739. onDestroy : function(){
  8740. this.stopMonitoring();
  8741. this.statusBar.statusEl.un('click', this.onStatusClick, this);
  8742. Ext.ux.ValidationStatus.superclass.onDestroy.call(this);
  8743. },
  8744. // private
  8745. onFieldValidation : function(f, msg){
  8746. if(!this.monitor){
  8747. return false;
  8748. }
  8749. if(msg){
  8750. this.errors.add(f.id, {field:f, msg:msg});
  8751. }else{
  8752. this.errors.removeKey(f.id);
  8753. }
  8754. this.updateErrorList();
  8755. if(this.errors.getCount() > 0){
  8756. if(this.statusBar.getText() != this.showText){
  8757. this.statusBar.setStatus({text:this.showText, iconCls:this.errorIconCls});
  8758. }
  8759. }else{
  8760. this.statusBar.clearStatus().setIcon(this.validIconCls);
  8761. }
  8762. },
  8763. // private
  8764. updateErrorList : function(){
  8765. if(this.errors.getCount() > 0){
  8766. var msg = '<ul>';
  8767. this.errors.each(function(err){
  8768. msg += ('<li id="x-err-'+ err.field.id +'"><a href="#">' + err.msg + '</a></li>');
  8769. }, this);
  8770. this.getMsgEl().update(msg+'</ul>');
  8771. }else{
  8772. this.getMsgEl().update('');
  8773. }
  8774. },
  8775. // private
  8776. getMsgEl : function(){
  8777. if(!this.msgEl){
  8778. this.msgEl = Ext.DomHelper.append(Ext.getBody(), {
  8779. cls: this.errorListCls+' x-hide-offsets'
  8780. }, true);
  8781. this.msgEl.on('click', function(e){
  8782. var t = e.getTarget('li', 10, true);
  8783. if(t){
  8784. Ext.getCmp(t.id.split('x-err-')[1]).focus();
  8785. this.hideErrors();
  8786. }
  8787. }, this, {stopEvent:true}); // prevent anchor click navigation
  8788. }
  8789. return this.msgEl;
  8790. },
  8791. // private
  8792. showErrors : function(){
  8793. this.updateErrorList();
  8794. this.getMsgEl().alignTo(this.statusBar.getEl(), this.listAlign).slideIn('b', {duration:0.3, easing:'easeOut'});
  8795. this.statusBar.setText(this.hideText);
  8796. this.form.getEl().on('click', this.hideErrors, this, {single:true}); // hide if the user clicks directly into the form
  8797. },
  8798. // private
  8799. hideErrors : function(){
  8800. var el = this.getMsgEl();
  8801. if(el.isVisible()){
  8802. el.slideOut('b', {duration:0.2, easing:'easeIn'});
  8803. this.statusBar.setText(this.showText);
  8804. }
  8805. this.form.getEl().un('click', this.hideErrors, this);
  8806. },
  8807. // private
  8808. onStatusClick : function(){
  8809. if(this.getMsgEl().isVisible()){
  8810. this.hideErrors();
  8811. }else if(this.errors.getCount() > 0){
  8812. this.showErrors();
  8813. }
  8814. }
  8815. });(function() {
  8816. Ext.override(Ext.list.Column, {
  8817. init : function() {
  8818. var types = Ext.data.Types,
  8819. st = this.sortType;
  8820. if(this.type){
  8821. if(Ext.isString(this.type)){
  8822. this.type = Ext.data.Types[this.type.toUpperCase()] || types.AUTO;
  8823. }
  8824. }else{
  8825. this.type = types.AUTO;
  8826. }
  8827. // named sortTypes are supported, here we look them up
  8828. if(Ext.isString(st)){
  8829. this.sortType = Ext.data.SortTypes[st];
  8830. }else if(Ext.isEmpty(st)){
  8831. this.sortType = this.type.sortType;
  8832. }
  8833. }
  8834. });
  8835. Ext.tree.Column = Ext.extend(Ext.list.Column, {});
  8836. Ext.tree.NumberColumn = Ext.extend(Ext.list.NumberColumn, {});
  8837. Ext.tree.DateColumn = Ext.extend(Ext.list.DateColumn, {});
  8838. Ext.tree.BooleanColumn = Ext.extend(Ext.list.BooleanColumn, {});
  8839. Ext.reg('tgcolumn', Ext.tree.Column);
  8840. Ext.reg('tgnumbercolumn', Ext.tree.NumberColumn);
  8841. Ext.reg('tgdatecolumn', Ext.tree.DateColumn);
  8842. Ext.reg('tgbooleancolumn', Ext.tree.BooleanColumn);
  8843. })();
  8844. /**
  8845. * @class Ext.ux.tree.TreeGridNodeUI
  8846. * @extends Ext.tree.TreeNodeUI
  8847. */
  8848. Ext.ux.tree.TreeGridNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  8849. isTreeGridNodeUI: true,
  8850. renderElements : function(n, a, targetNode, bulkRender){
  8851. var t = n.getOwnerTree(),
  8852. cols = t.columns,
  8853. c = cols[0],
  8854. i, buf, len;
  8855. this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
  8856. buf = [
  8857. '<tbody class="x-tree-node">',
  8858. '<tr ext:tree-node-id="', n.id ,'" class="x-tree-node-el x-tree-node-leaf ', a.cls, '">',
  8859. '<td class="x-treegrid-col">',
  8860. '<span class="x-tree-node-indent">', this.indentMarkup, "</span>",
  8861. '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
  8862. '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon', (a.icon ? " x-tree-node-inline-icon" : ""), (a.iconCls ? " "+a.iconCls : ""), '" unselectable="on" />',
  8863. '<a hidefocus="on" class="x-tree-node-anchor" href="', a.href ? a.href : '#', '" tabIndex="1" ',
  8864. a.hrefTarget ? ' target="'+a.hrefTarget+'"' : '', '>',
  8865. '<span unselectable="on">', (c.tpl ? c.tpl.apply(a) : a[c.dataIndex] || c.text), '</span></a>',
  8866. '</td>'
  8867. ];
  8868. for(i = 1, len = cols.length; i < len; i++){
  8869. c = cols[i];
  8870. buf.push(
  8871. '<td class="x-treegrid-col ', (c.cls ? c.cls : ''), '">',
  8872. '<div unselectable="on" class="x-treegrid-text"', (c.align ? ' style="text-align: ' + c.align + ';"' : ''), '>',
  8873. (c.tpl ? c.tpl.apply(a) : a[c.dataIndex]),
  8874. '</div>',
  8875. '</td>'
  8876. );
  8877. }
  8878. buf.push(
  8879. '</tr><tr class="x-tree-node-ct"><td colspan="', cols.length, '">',
  8880. '<table class="x-treegrid-node-ct-table" cellpadding="0" cellspacing="0" style="table-layout: fixed; display: none; width: ', t.innerCt.getWidth() ,'px;"><colgroup>'
  8881. );
  8882. for(i = 0, len = cols.length; i<len; i++) {
  8883. buf.push('<col style="width: ', (cols[i].hidden ? 0 : cols[i].width) ,'px;" />');
  8884. }
  8885. buf.push('</colgroup></table></td></tr></tbody>');
  8886. if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
  8887. this.wrap = Ext.DomHelper.insertHtml("beforeBegin", n.nextSibling.ui.getEl(), buf.join(''));
  8888. }else{
  8889. this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(''));
  8890. }
  8891. this.elNode = this.wrap.childNodes[0];
  8892. this.ctNode = this.wrap.childNodes[1].firstChild.firstChild;
  8893. var cs = this.elNode.firstChild.childNodes;
  8894. this.indentNode = cs[0];
  8895. this.ecNode = cs[1];
  8896. this.iconNode = cs[2];
  8897. this.anchor = cs[3];
  8898. this.textNode = cs[3].firstChild;
  8899. },
  8900. // private
  8901. animExpand : function(cb){
  8902. this.ctNode.style.display = "";
  8903. Ext.ux.tree.TreeGridNodeUI.superclass.animExpand.call(this, cb);
  8904. }
  8905. });
  8906. Ext.ux.tree.TreeGridRootNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
  8907. isTreeGridNodeUI: true,
  8908. // private
  8909. render : function(){
  8910. if(!this.rendered){
  8911. this.wrap = this.ctNode = this.node.ownerTree.innerCt.dom;
  8912. this.node.expanded = true;
  8913. }
  8914. if(Ext.isWebKit) {
  8915. // weird table-layout: fixed issue in webkit
  8916. var ct = this.ctNode;
  8917. ct.style.tableLayout = null;
  8918. (function() {
  8919. ct.style.tableLayout = 'fixed';
  8920. }).defer(1);
  8921. }
  8922. },
  8923. destroy : function(){
  8924. if(this.elNode){
  8925. Ext.dd.Registry.unregister(this.elNode.id);
  8926. }
  8927. delete this.node;
  8928. },
  8929. collapse : Ext.emptyFn,
  8930. expand : Ext.emptyFn
  8931. });/**
  8932. * @class Ext.tree.ColumnResizer
  8933. * @extends Ext.util.Observable
  8934. */
  8935. Ext.tree.ColumnResizer = Ext.extend(Ext.util.Observable, {
  8936. /**
  8937. * @cfg {Number} minWidth The minimum width the column can be dragged to.
  8938. * Defaults to <tt>14</tt>.
  8939. */
  8940. minWidth: 14,
  8941. constructor: function(config){
  8942. Ext.apply(this, config);
  8943. Ext.tree.ColumnResizer.superclass.constructor.call(this);
  8944. },
  8945. init : function(tree){
  8946. this.tree = tree;
  8947. tree.on('render', this.initEvents, this);
  8948. },
  8949. initEvents : function(tree){
  8950. tree.mon(tree.innerHd, 'mousemove', this.handleHdMove, this);
  8951. this.tracker = new Ext.dd.DragTracker({
  8952. onBeforeStart: this.onBeforeStart.createDelegate(this),
  8953. onStart: this.onStart.createDelegate(this),
  8954. onDrag: this.onDrag.createDelegate(this),
  8955. onEnd: this.onEnd.createDelegate(this),
  8956. tolerance: 3,
  8957. autoStart: 300
  8958. });
  8959. this.tracker.initEl(tree.innerHd);
  8960. tree.on('beforedestroy', this.tracker.destroy, this.tracker);
  8961. },
  8962. handleHdMove : function(e, t){
  8963. var hw = 5,
  8964. x = e.getPageX(),
  8965. hd = e.getTarget('.x-treegrid-hd', 3, true);
  8966. if(hd){
  8967. var r = hd.getRegion(),
  8968. ss = hd.dom.style,
  8969. pn = hd.dom.parentNode;
  8970. if(x - r.left <= hw && hd.dom !== pn.firstChild) {
  8971. var ps = hd.dom.previousSibling;
  8972. while(ps && Ext.fly(ps).hasClass('x-treegrid-hd-hidden')) {
  8973. ps = ps.previousSibling;
  8974. }
  8975. if(ps) {
  8976. this.activeHd = Ext.get(ps);
  8977. ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize';
  8978. }
  8979. } else if(r.right - x <= hw) {
  8980. var ns = hd.dom;
  8981. while(ns && Ext.fly(ns).hasClass('x-treegrid-hd-hidden')) {
  8982. ns = ns.previousSibling;
  8983. }
  8984. if(ns) {
  8985. this.activeHd = Ext.get(ns);
  8986. ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize';
  8987. }
  8988. } else{
  8989. delete this.activeHd;
  8990. ss.cursor = '';
  8991. }
  8992. }
  8993. },
  8994. onBeforeStart : function(e){
  8995. this.dragHd = this.activeHd;
  8996. return !!this.dragHd;
  8997. },
  8998. onStart : function(e){
  8999. this.dragHeadersDisabled = this.tree.headersDisabled;
  9000. this.tree.headersDisabled = true;
  9001. this.proxy = this.tree.body.createChild({cls:'x-treegrid-resizer'});
  9002. this.proxy.setHeight(this.tree.body.getHeight());
  9003. var x = this.tracker.getXY()[0];
  9004. this.hdX = this.dragHd.getX();
  9005. this.hdIndex = this.tree.findHeaderIndex(this.dragHd);
  9006. this.proxy.setX(this.hdX);
  9007. this.proxy.setWidth(x-this.hdX);
  9008. this.maxWidth = this.tree.outerCt.getWidth() - this.tree.innerBody.translatePoints(this.hdX).left;
  9009. },
  9010. onDrag : function(e){
  9011. var cursorX = this.tracker.getXY()[0];
  9012. this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth));
  9013. },
  9014. onEnd : function(e){
  9015. var nw = this.proxy.getWidth(),
  9016. tree = this.tree,
  9017. disabled = this.dragHeadersDisabled;
  9018. this.proxy.remove();
  9019. delete this.dragHd;
  9020. tree.columns[this.hdIndex].width = nw;
  9021. tree.updateColumnWidths();
  9022. setTimeout(function(){
  9023. tree.headersDisabled = disabled;
  9024. }, 100);
  9025. }
  9026. });Ext.ns('Ext.ux.tree');
  9027. /**
  9028. * @class Ext.ux.tree.TreeGridSorter
  9029. * @extends Ext.tree.TreeSorter
  9030. * Provides sorting of nodes in a {@link Ext.ux.tree.TreeGrid}. The TreeGridSorter automatically monitors events on the
  9031. * associated TreeGrid that might affect the tree's sort order (beforechildrenrendered, append, insert and textchange).
  9032. * Example usage:<br />
  9033. * <pre><code>
  9034. new Ext.ux.tree.TreeGridSorter(myTreeGrid, {
  9035. folderSort: true,
  9036. dir: "desc",
  9037. sortType: function(node) {
  9038. // sort by a custom, typed attribute:
  9039. return parseInt(node.id, 10);
  9040. }
  9041. });
  9042. </code></pre>
  9043. * @constructor
  9044. * @param {TreeGrid} tree
  9045. * @param {Object} config
  9046. */
  9047. Ext.ux.tree.TreeGridSorter = Ext.extend(Ext.tree.TreeSorter, {
  9048. /**
  9049. * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to <tt>['sort-asc', 'sort-desc']</tt>)
  9050. */
  9051. sortClasses : ['sort-asc', 'sort-desc'],
  9052. /**
  9053. * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to <tt>'Sort Ascending'</tt>)
  9054. */
  9055. sortAscText : 'Sort Ascending',
  9056. /**
  9057. * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to <tt>'Sort Descending'</tt>)
  9058. */
  9059. sortDescText : 'Sort Descending',
  9060. constructor : function(tree, config) {
  9061. if(!Ext.isObject(config)) {
  9062. config = {
  9063. property: tree.columns[0].dataIndex || 'text',
  9064. folderSort: true
  9065. }
  9066. }
  9067. Ext.ux.tree.TreeGridSorter.superclass.constructor.apply(this, arguments);
  9068. this.tree = tree;
  9069. tree.on('headerclick', this.onHeaderClick, this);
  9070. tree.ddAppendOnly = true;
  9071. var me = this;
  9072. this.defaultSortFn = function(n1, n2){
  9073. var desc = me.dir && me.dir.toLowerCase() == 'desc',
  9074. prop = me.property || 'text',
  9075. sortType = me.sortType,
  9076. caseSensitive = me.caseSensitive === true,
  9077. leafAttr = me.leafAttr || 'leaf',
  9078. attr1 = n1.attributes,
  9079. attr2 = n2.attributes;
  9080. if(me.folderSort){
  9081. if(attr1[leafAttr] && !attr2[leafAttr]){
  9082. return 1;
  9083. }
  9084. if(!attr1[leafAttr] && attr2[leafAttr]){
  9085. return -1;
  9086. }
  9087. }
  9088. var prop1 = attr1[prop],
  9089. prop2 = attr2[prop],
  9090. v1 = sortType ? sortType(prop1) : (caseSensitive ? prop1 : prop1.toUpperCase());
  9091. v2 = sortType ? sortType(prop2) : (caseSensitive ? prop2 : prop2.toUpperCase());
  9092. if(v1 < v2){
  9093. return desc ? +1 : -1;
  9094. }else if(v1 > v2){
  9095. return desc ? -1 : +1;
  9096. }else{
  9097. return 0;
  9098. }
  9099. };
  9100. tree.on('afterrender', this.onAfterTreeRender, this, {single: true});
  9101. tree.on('headermenuclick', this.onHeaderMenuClick, this);
  9102. },
  9103. onAfterTreeRender : function() {
  9104. if(this.tree.hmenu){
  9105. this.tree.hmenu.insert(0,
  9106. {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'},
  9107. {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'}
  9108. );
  9109. }
  9110. this.updateSortIcon(0, 'asc');
  9111. },
  9112. onHeaderMenuClick : function(c, id, index) {
  9113. if(id === 'asc' || id === 'desc') {
  9114. this.onHeaderClick(c, null, index);
  9115. return false;
  9116. }
  9117. },
  9118. onHeaderClick : function(c, el, i) {
  9119. if(c && !this.tree.headersDisabled){
  9120. var me = this;
  9121. me.property = c.dataIndex;
  9122. me.dir = c.dir = (c.dir === 'desc' ? 'asc' : 'desc');
  9123. me.sortType = c.sortType;
  9124. me.caseSensitive === Ext.isBoolean(c.caseSensitive) ? c.caseSensitive : this.caseSensitive;
  9125. me.sortFn = c.sortFn || this.defaultSortFn;
  9126. this.tree.root.cascade(function(n) {
  9127. if(!n.isLeaf()) {
  9128. me.updateSort(me.tree, n);
  9129. }
  9130. });
  9131. this.updateSortIcon(i, c.dir);
  9132. }
  9133. },
  9134. // private
  9135. updateSortIcon : function(col, dir){
  9136. var sc = this.sortClasses,
  9137. hds = this.tree.innerHd.select('td').removeClass(sc);
  9138. hds.item(col).addClass(sc[dir == 'desc' ? 1 : 0]);
  9139. }
  9140. });/**
  9141. * @class Ext.ux.tree.TreeGridLoader
  9142. * @extends Ext.tree.TreeLoader
  9143. */
  9144. Ext.ux.tree.TreeGridLoader = Ext.extend(Ext.tree.TreeLoader, {
  9145. createNode : function(attr) {
  9146. if (!attr.uiProvider) {
  9147. attr.uiProvider = Ext.ux.tree.TreeGridNodeUI;
  9148. }
  9149. return Ext.tree.TreeLoader.prototype.createNode.call(this, attr);
  9150. }
  9151. });/**
  9152. * @class Ext.ux.tree.TreeGrid
  9153. * @extends Ext.tree.TreePanel
  9154. *
  9155. * @xtype treegrid
  9156. */
  9157. Ext.ux.tree.TreeGrid = Ext.extend(Ext.tree.TreePanel, {
  9158. rootVisible : false,
  9159. useArrows : true,
  9160. lines : false,
  9161. borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell
  9162. cls : 'x-treegrid',
  9163. columnResize : true,
  9164. enableSort : true,
  9165. reserveScrollOffset : true,
  9166. enableHdMenu : true,
  9167. columnsText : 'Columns',
  9168. initComponent : function() {
  9169. if(!this.root) {
  9170. this.root = new Ext.tree.AsyncTreeNode({text: 'Root'});
  9171. }
  9172. // initialize the loader
  9173. var l = this.loader;
  9174. if(!l){
  9175. l = new Ext.ux.tree.TreeGridLoader({
  9176. dataUrl: this.dataUrl,
  9177. requestMethod: this.requestMethod,
  9178. store: this.store
  9179. });
  9180. }else if(Ext.isObject(l) && !l.load){
  9181. l = new Ext.ux.tree.TreeGridLoader(l);
  9182. }
  9183. this.loader = l;
  9184. Ext.ux.tree.TreeGrid.superclass.initComponent.call(this);
  9185. this.initColumns();
  9186. if(this.enableSort) {
  9187. this.treeGridSorter = new Ext.ux.tree.TreeGridSorter(this, this.enableSort);
  9188. }
  9189. if(this.columnResize){
  9190. this.colResizer = new Ext.tree.ColumnResizer(this.columnResize);
  9191. this.colResizer.init(this);
  9192. }
  9193. var c = this.columns;
  9194. if(!this.internalTpl){
  9195. this.internalTpl = new Ext.XTemplate(
  9196. '<div class="x-grid3-header">',
  9197. '<div class="x-treegrid-header-inner">',
  9198. '<div class="x-grid3-header-offset">',
  9199. '<table style="table-layout: fixed;" cellspacing="0" cellpadding="0" border="0"><colgroup><tpl for="columns"><col /></tpl></colgroup>',
  9200. '<thead><tr class="x-grid3-hd-row">',
  9201. '<tpl for="columns">',
  9202. '<td class="x-grid3-hd x-grid3-cell x-treegrid-hd" style="text-align: {align};" id="', this.id, '-xlhd-{#}">',
  9203. '<div class="x-grid3-hd-inner x-treegrid-hd-inner" unselectable="on">',
  9204. this.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
  9205. '{header}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
  9206. '</div>',
  9207. '</td></tpl>',
  9208. '</tr></thead>',
  9209. '</table>',
  9210. '</div></div>',
  9211. '</div>',
  9212. '<div class="x-treegrid-root-node">',
  9213. '<table class="x-treegrid-root-table" cellpadding="0" cellspacing="0" style="table-layout: fixed;"></table>',
  9214. '</div>'
  9215. );
  9216. }
  9217. if(!this.colgroupTpl) {
  9218. this.colgroupTpl = new Ext.XTemplate(
  9219. '<colgroup><tpl for="columns"><col style="width: {width}px"/></tpl></colgroup>'
  9220. );
  9221. }
  9222. },
  9223. initColumns : function() {
  9224. var cs = this.columns,
  9225. len = cs.length,
  9226. columns = [],
  9227. i, c;
  9228. for(i = 0; i < len; i++){
  9229. c = cs[i];
  9230. if(!c.isColumn) {
  9231. c.xtype = c.xtype ? (/^tg/.test(c.xtype) ? c.xtype : 'tg' + c.xtype) : 'tgcolumn';
  9232. c = Ext.create(c);
  9233. }
  9234. c.init(this);
  9235. columns.push(c);
  9236. if(this.enableSort !== false && c.sortable !== false) {
  9237. c.sortable = true;
  9238. this.enableSort = true;
  9239. }
  9240. }
  9241. this.columns = columns;
  9242. },
  9243. onRender : function(){
  9244. Ext.tree.TreePanel.superclass.onRender.apply(this, arguments);
  9245. this.el.addClass('x-treegrid');
  9246. this.outerCt = this.body.createChild({
  9247. cls:'x-tree-root-ct x-treegrid-ct ' + (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines')
  9248. });
  9249. this.internalTpl.overwrite(this.outerCt, {columns: this.columns});
  9250. this.mainHd = Ext.get(this.outerCt.dom.firstChild);
  9251. this.innerHd = Ext.get(this.mainHd.dom.firstChild);
  9252. this.innerBody = Ext.get(this.outerCt.dom.lastChild);
  9253. this.innerCt = Ext.get(this.innerBody.dom.firstChild);
  9254. this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
  9255. if(this.hideHeaders){
  9256. this.el.child('.x-grid3-header').setDisplayed('none');
  9257. }
  9258. else if(this.enableHdMenu !== false){
  9259. this.hmenu = new Ext.menu.Menu({id: this.id + '-hctx'});
  9260. if(this.enableColumnHide !== false){
  9261. this.colMenu = new Ext.menu.Menu({id: this.id + '-hcols-menu'});
  9262. this.colMenu.on({
  9263. scope: this,
  9264. beforeshow: this.beforeColMenuShow,
  9265. itemclick: this.handleHdMenuClick
  9266. });
  9267. this.hmenu.add({
  9268. itemId:'columns',
  9269. hideOnClick: false,
  9270. text: this.columnsText,
  9271. menu: this.colMenu,
  9272. iconCls: 'x-cols-icon'
  9273. });
  9274. }
  9275. this.hmenu.on('itemclick', this.handleHdMenuClick, this);
  9276. }
  9277. },
  9278. setRootNode : function(node){
  9279. node.attributes.uiProvider = Ext.ux.tree.TreeGridRootNodeUI;
  9280. node = Ext.ux.tree.TreeGrid.superclass.setRootNode.call(this, node);
  9281. if(this.innerCt) {
  9282. this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns});
  9283. }
  9284. return node;
  9285. },
  9286. clearInnerCt : function(){
  9287. if(Ext.isIE){
  9288. var dom = this.innerCt.dom;
  9289. while(dom.firstChild){
  9290. dom.removeChild(dom.firstChild);
  9291. }
  9292. }else{
  9293. Ext.ux.tree.TreeGrid.superclass.clearInnerCt.call(this);
  9294. }
  9295. },
  9296. initEvents : function() {
  9297. Ext.ux.tree.TreeGrid.superclass.initEvents.apply(this, arguments);
  9298. this.mon(this.innerBody, 'scroll', this.syncScroll, this);
  9299. this.mon(this.innerHd, 'click', this.handleHdDown, this);
  9300. this.mon(this.mainHd, {
  9301. scope: this,
  9302. mouseover: this.handleHdOver,
  9303. mouseout: this.handleHdOut
  9304. });
  9305. },
  9306. onResize : function(w, h) {
  9307. Ext.ux.tree.TreeGrid.superclass.onResize.apply(this, arguments);
  9308. var bd = this.innerBody.dom;
  9309. var hd = this.innerHd.dom;
  9310. if(!bd){
  9311. return;
  9312. }
  9313. if(Ext.isNumber(h)){
  9314. bd.style.height = this.body.getHeight(true) - hd.offsetHeight + 'px';
  9315. }
  9316. if(Ext.isNumber(w)){
  9317. var sw = Ext.num(this.scrollOffset, Ext.getScrollBarWidth());
  9318. if(this.reserveScrollOffset || ((bd.offsetWidth - bd.clientWidth) > 10)){
  9319. this.setScrollOffset(sw);
  9320. }else{
  9321. var me = this;
  9322. setTimeout(function(){
  9323. me.setScrollOffset(bd.offsetWidth - bd.clientWidth > 10 ? sw : 0);
  9324. }, 10);
  9325. }
  9326. }
  9327. },
  9328. updateColumnWidths : function() {
  9329. var cols = this.columns,
  9330. colCount = cols.length,
  9331. groups = this.outerCt.query('colgroup'),
  9332. groupCount = groups.length,
  9333. c, g, i, j;
  9334. for(i = 0; i<colCount; i++) {
  9335. c = cols[i];
  9336. for(j = 0; j<groupCount; j++) {
  9337. g = groups[j];
  9338. g.childNodes[i].style.width = (c.hidden ? 0 : c.width) + 'px';
  9339. }
  9340. }
  9341. for(i = 0, groups = this.innerHd.query('td'), len = groups.length; i<len; i++) {
  9342. c = Ext.fly(groups[i]);
  9343. if(cols[i] && cols[i].hidden) {
  9344. c.addClass('x-treegrid-hd-hidden');
  9345. }
  9346. else {
  9347. c.removeClass('x-treegrid-hd-hidden');
  9348. }
  9349. }
  9350. var tcw = this.getTotalColumnWidth();
  9351. Ext.fly(this.innerHd.dom.firstChild).setWidth(tcw + (this.scrollOffset || 0));
  9352. this.outerCt.select('table').setWidth(tcw);
  9353. this.syncHeaderScroll();
  9354. },
  9355. getVisibleColumns : function() {
  9356. var columns = [],
  9357. cs = this.columns,
  9358. len = cs.length,
  9359. i;
  9360. for(i = 0; i<len; i++) {
  9361. if(!cs[i].hidden) {
  9362. columns.push(cs[i]);
  9363. }
  9364. }
  9365. return columns;
  9366. },
  9367. getTotalColumnWidth : function() {
  9368. var total = 0;
  9369. for(var i = 0, cs = this.getVisibleColumns(), len = cs.length; i<len; i++) {
  9370. total += cs[i].width;
  9371. }
  9372. return total;
  9373. },
  9374. setScrollOffset : function(scrollOffset) {
  9375. this.scrollOffset = scrollOffset;
  9376. this.updateColumnWidths();
  9377. },
  9378. // private
  9379. handleHdDown : function(e, t){
  9380. var hd = e.getTarget('.x-treegrid-hd');
  9381. if(hd && Ext.fly(t).hasClass('x-grid3-hd-btn')){
  9382. var ms = this.hmenu.items,
  9383. cs = this.columns,
  9384. index = this.findHeaderIndex(hd),
  9385. c = cs[index],
  9386. sort = c.sortable;
  9387. e.stopEvent();
  9388. Ext.fly(hd).addClass('x-grid3-hd-menu-open');
  9389. this.hdCtxIndex = index;
  9390. this.fireEvent('headerbuttonclick', ms, c, hd, index);
  9391. this.hmenu.on('hide', function(){
  9392. Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
  9393. }, this, {single:true});
  9394. this.hmenu.show(t, 'tl-bl?');
  9395. }
  9396. else if(hd) {
  9397. var index = this.findHeaderIndex(hd);
  9398. this.fireEvent('headerclick', this.columns[index], hd, index);
  9399. }
  9400. },
  9401. // private
  9402. handleHdOver : function(e, t){
  9403. var hd = e.getTarget('.x-treegrid-hd');
  9404. if(hd && !this.headersDisabled){
  9405. index = this.findHeaderIndex(hd);
  9406. this.activeHdRef = t;
  9407. this.activeHdIndex = index;
  9408. var el = Ext.get(hd);
  9409. this.activeHdRegion = el.getRegion();
  9410. el.addClass('x-grid3-hd-over');
  9411. this.activeHdBtn = el.child('.x-grid3-hd-btn');
  9412. if(this.activeHdBtn){
  9413. this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
  9414. }
  9415. }
  9416. },
  9417. // private
  9418. handleHdOut : function(e, t){
  9419. var hd = e.getTarget('.x-treegrid-hd');
  9420. if(hd && (!Ext.isIE || !e.within(hd, true))){
  9421. this.activeHdRef = null;
  9422. Ext.fly(hd).removeClass('x-grid3-hd-over');
  9423. hd.style.cursor = '';
  9424. }
  9425. },
  9426. findHeaderIndex : function(hd){
  9427. hd = hd.dom || hd;
  9428. var cs = hd.parentNode.childNodes;
  9429. for(var i = 0, c; c = cs[i]; i++){
  9430. if(c == hd){
  9431. return i;
  9432. }
  9433. }
  9434. return -1;
  9435. },
  9436. // private
  9437. beforeColMenuShow : function(){
  9438. var cols = this.columns,
  9439. colCount = cols.length,
  9440. i, c;
  9441. this.colMenu.removeAll();
  9442. for(i = 1; i < colCount; i++){
  9443. c = cols[i];
  9444. if(c.hideable !== false){
  9445. this.colMenu.add(new Ext.menu.CheckItem({
  9446. itemId: 'col-' + i,
  9447. text: c.header,
  9448. checked: !c.hidden,
  9449. hideOnClick:false,
  9450. disabled: c.hideable === false
  9451. }));
  9452. }
  9453. }
  9454. },
  9455. // private
  9456. handleHdMenuClick : function(item){
  9457. var index = this.hdCtxIndex,
  9458. id = item.getItemId();
  9459. if(this.fireEvent('headermenuclick', this.columns[index], id, index) !== false) {
  9460. index = id.substr(4);
  9461. if(index > 0 && this.columns[index]) {
  9462. this.setColumnVisible(index, !item.checked);
  9463. }
  9464. }
  9465. return true;
  9466. },
  9467. setColumnVisible : function(index, visible) {
  9468. this.columns[index].hidden = !visible;
  9469. this.updateColumnWidths();
  9470. },
  9471. /**
  9472. * Scrolls the grid to the top
  9473. */
  9474. scrollToTop : function(){
  9475. this.innerBody.dom.scrollTop = 0;
  9476. this.innerBody.dom.scrollLeft = 0;
  9477. },
  9478. // private
  9479. syncScroll : function(){
  9480. this.syncHeaderScroll();
  9481. var mb = this.innerBody.dom;
  9482. this.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop);
  9483. },
  9484. // private
  9485. syncHeaderScroll : function(){
  9486. var mb = this.innerBody.dom;
  9487. this.innerHd.dom.scrollLeft = mb.scrollLeft;
  9488. this.innerHd.dom.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
  9489. },
  9490. registerNode : function(n) {
  9491. Ext.ux.tree.TreeGrid.superclass.registerNode.call(this, n);
  9492. if(!n.uiProvider && !n.isRoot && !n.ui.isTreeGridNodeUI) {
  9493. n.ui = new Ext.ux.tree.TreeGridNodeUI(n);
  9494. }
  9495. }
  9496. });
  9497. Ext.reg('treegrid', Ext.ux.tree.TreeGrid);