]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * A simple progress bar widget.\r | |
3 | *\r | |
4 | * You are responsible for showing, updating (via {@link #setValue}) and clearing the\r | |
5 | * progress bar as needed from your own code. This method is most appropriate when you\r | |
6 | * want to show progress throughout an operation that has predictable points of interest\r | |
7 | * at which you can update the control.\r | |
8 | *\r | |
9 | * @example\r | |
10 | * var store = Ext.create('Ext.data.Store', {\r | |
11 | * fields: ['name', 'progress'],\r | |
12 | * data: [\r | |
13 | * { name: 'Lisa', progress: .159 },\r | |
14 | * { name: 'Bart', progress: .216 },\r | |
15 | * { name: 'Homer', progress: .55 },\r | |
16 | * { name: 'Maggie', progress: .167 },\r | |
17 | * { name: 'Marge', progress: .145 }\r | |
18 | * ]\r | |
19 | * });\r | |
20 | *\r | |
21 | * Ext.create('Ext.grid.Panel', {\r | |
22 | * title: 'Simpsons',\r | |
23 | * store: store,\r | |
24 | * columns: [\r | |
25 | * { text: 'Name', dataIndex: 'name' },\r | |
26 | * {\r | |
27 | * text: 'Progress',\r | |
28 | * xtype: 'widgetcolumn',\r | |
29 | * width: 120,\r | |
30 | * dataIndex: 'progress',\r | |
31 | * widget: {\r | |
32 | * xtype: 'progress'\r | |
33 | * }\r | |
34 | * }\r | |
35 | * ],\r | |
36 | * height: 200,\r | |
37 | * width: 400,\r | |
38 | * renderTo: Ext.getBody()\r | |
39 | * });\r | |
40 | *\r | |
41 | */\r | |
42 | Ext.define('Ext.Progress', {\r | |
43 | extend: 'Ext.Widget',\r | |
44 | xtype: [ 'progress', 'progressbarwidget' ],\r | |
45 | alternateClassName: 'Ext.ProgressBarWidget',\r | |
46 | \r | |
47 | mixins: [\r | |
48 | 'Ext.ProgressBase'\r | |
49 | ],\r | |
50 | \r | |
51 | config: {\r | |
52 | /**\r | |
53 | * @cfg {String} [text]\r | |
54 | * The background text\r | |
55 | */\r | |
56 | text: null,\r | |
57 | \r | |
58 | /**\r | |
59 | * @cfg {Boolean} [animate=false]\r | |
60 | * Specify as `true` to have this progress bar animate to new extent when updated.\r | |
61 | */\r | |
62 | animate: false\r | |
63 | },\r | |
64 | \r | |
65 | cachedConfig: {\r | |
66 | /**\r | |
67 | * @cfg {String} [baseCls='x-progress']\r | |
68 | * The base CSS class to apply to the progress bar's wrapper element.\r | |
69 | */\r | |
70 | baseCls: Ext.baseCSSPrefix + 'progress',\r | |
71 | \r | |
72 | textCls: Ext.baseCSSPrefix + 'progress-text',\r | |
73 | \r | |
74 | cls: null,\r | |
75 | \r | |
76 | ui: null\r | |
77 | },\r | |
78 | \r | |
79 | template: [{\r | |
80 | reference: 'backgroundEl'\r | |
81 | }, {\r | |
82 | reference: 'barEl',\r | |
83 | children: [{\r | |
84 | reference: 'textEl'\r | |
85 | }]\r | |
86 | }],\r | |
87 | \r | |
88 | defaultBindProperty: 'value',\r | |
89 | \r | |
90 | updateWidth: function(width, oldWidth) {\r | |
91 | var me = this;\r | |
92 | \r | |
93 | me.callParent([width, oldWidth]);\r | |
94 | width -= me.element.getBorderWidth('lr');\r | |
95 | me.backgroundEl.setWidth(width);\r | |
96 | me.textEl.setWidth(width);\r | |
97 | },\r | |
98 | \r | |
99 | updateCls: function(cls, oldCls) {\r | |
100 | var el = this.element;\r | |
101 | \r | |
102 | if (oldCls) {\r | |
103 | el.removeCls(oldCls);\r | |
104 | }\r | |
105 | \r | |
106 | if (cls) {\r | |
107 | el.addCls(cls);\r | |
108 | }\r | |
109 | },\r | |
110 | \r | |
111 | updateUi: function(ui, oldUi) {\r | |
112 | var element = this.element,\r | |
113 | barEl = this.barEl,\r | |
114 | baseCls = this.getBaseCls() + '-';\r | |
115 | \r | |
116 | if (oldUi) {\r | |
117 | element.removeCls(baseCls + oldUi);\r | |
118 | barEl.removeCls(baseCls + 'bar-' + oldUi);\r | |
119 | }\r | |
120 | \r | |
121 | element.addCls(baseCls + ui);\r | |
122 | barEl.addCls(baseCls + 'bar-' + ui);\r | |
123 | },\r | |
124 | \r | |
125 | updateBaseCls: function(baseCls, oldBaseCls) {\r | |
126 | //<debug>\r | |
127 | if (oldBaseCls) {\r | |
128 | Ext.raise('You cannot configure baseCls - use a subclass');\r | |
129 | }\r | |
130 | //</debug>\r | |
131 | this.element.addCls(baseCls);\r | |
132 | this.barEl.addCls(baseCls + '-bar');\r | |
133 | },\r | |
134 | \r | |
135 | updateTextCls: function(textCls) {\r | |
136 | this.backgroundEl.addCls(textCls + ' ' + textCls + '-back');\r | |
137 | this.textEl.addCls(textCls);\r | |
138 | },\r | |
139 | \r | |
140 | updateValue: function(value, oldValue) {\r | |
141 | var me = this,\r | |
142 | barEl = me.barEl,\r | |
143 | textTpl = me.getTextTpl();\r | |
144 | \r | |
145 | if (textTpl) {\r | |
146 | me.setText(textTpl.apply({\r | |
147 | value: value,\r | |
148 | percent: Math.round(value * 100)\r | |
149 | }));\r | |
150 | }\r | |
151 | if (me.getAnimate()) {\r | |
152 | barEl.stopAnimation();\r | |
153 | barEl.animate(Ext.apply({\r | |
154 | from: {\r | |
155 | width: (oldValue * 100) + '%'\r | |
156 | },\r | |
157 | to: {\r | |
158 | width: (value * 100) + '%'\r | |
159 | }\r | |
160 | }, me.animate));\r | |
161 | } else {\r | |
162 | barEl.setStyle('width', (value * 100) + '%');\r | |
163 | }\r | |
164 | },\r | |
165 | \r | |
166 | updateText: function(text) {\r | |
167 | this.backgroundEl.setHtml(text);\r | |
168 | this.textEl.setHtml(text);\r | |
169 | }\r | |
170 | });\r |