Upgrade to ExtJS 3.2.1 - Released 04/27/2010
[extjs.git] / examples / ux / ProgressBarPager.js
1 /*!
2  * Ext JS Library 3.2.1
3  * Copyright(c) 2006-2010 Ext JS, Inc.
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**
8 * @class Ext.ux.ProgressBarPager
9 * @extends Object 
10 * Plugin (ptype = 'tabclosemenu') for displaying a progressbar inside of a paging toolbar instead of plain text
11
12 * @ptype progressbarpager 
13 * @constructor
14 * Create a new ItemSelector
15 * @param {Object} config Configuration options
16 * @xtype itemselector 
17 */
18 Ext.ux.ProgressBarPager  = Ext.extend(Object, {
19         /**
20         * @cfg {Integer} progBarWidth
21         * <p>The default progress bar width.  Default is 225.</p>
22         */
23         progBarWidth   : 225,
24         /**
25         * @cfg {String} defaultText
26         * <p>The text to display while the store is loading.  Default is 'Loading...'</p>
27         */
28         defaultText    : 'Loading...',
29         /**
30         * @cfg {Object} defaultAnimCfg 
31         * <p>A {@link Ext.Fx Ext.Fx} configuration object.  Default is  { duration : 1, easing : 'bounceOut' }.</p>
32         */
33         defaultAnimCfg : {
34                 duration   : 1,
35                 easing     : 'bounceOut'        
36         },                                                                                                
37         constructor : function(config) {
38                 if (config) {
39                         Ext.apply(this, config);
40                 }
41         },
42         //public
43         init : function (parent) {
44                 
45                 if(parent.displayInfo){
46                         this.parent = parent;
47                         var ind  = parent.items.indexOf(parent.displayItem);
48                         parent.remove(parent.displayItem, true);
49                         this.progressBar = new Ext.ProgressBar({
50                                 text    : this.defaultText,
51                                 width   : this.progBarWidth,
52                                 animate :  this.defaultAnimCfg
53                         });                                     
54                    
55                         parent.displayItem = this.progressBar;
56                         
57                         parent.add(parent.displayItem); 
58                         parent.doLayout();
59                         Ext.apply(parent, this.parentOverrides);                
60                         
61                         this.progressBar.on('render', function(pb) {
62                 pb.mon(pb.getEl().applyStyles('cursor:pointer'), 'click', this.handleProgressBarClick, this);
63             }, this, {single: true});
64                                                 
65                 }
66                   
67         },
68         // private
69         // This method handles the click for the progress bar
70         handleProgressBarClick : function(e){
71                 var parent = this.parent,
72                     displayItem = parent.displayItem,
73                     box = this.progressBar.getBox(),
74                     xy = e.getXY(),
75                     position = xy[0]-box.x,
76                     pages = Math.ceil(parent.store.getTotalCount()/parent.pageSize),
77                     newpage = Math.ceil(position/(displayItem.width/pages));
78             
79                 parent.changePage(newpage);
80         },
81         
82         // private, overriddes
83         parentOverrides  : {
84                 // private
85                 // This method updates the information via the progress bar.
86                 updateInfo : function(){
87                         if(this.displayItem){
88                                 var count = this.store.getCount(),
89                                     pgData = this.getPageData(),
90                                     pageNum = this.readPage(pgData),
91                                     msg = count == 0 ?
92                                         this.emptyMsg :
93                                         String.format(
94                                                 this.displayMsg,
95                                                 this.cursor+1, this.cursor+count, this.store.getTotalCount()
96                                         );
97                                         
98                                 pageNum = pgData.activePage; ;  
99                                 
100                                 var pct = pageNum / pgData.pages;       
101                                 
102                                 this.displayItem.updateProgress(pct, msg, this.animate || this.defaultAnimConfig);
103                         }
104                 }
105         }
106 });
107 Ext.preg('progressbarpager', Ext.ux.ProgressBarPager);
108