]> git.proxmox.com Git - extjs.git/blame - extjs/modern/modern/src/ProgressIndicator.js
add extjs 6.0.1 sources
[extjs.git] / extjs / modern / modern / src / ProgressIndicator.js
CommitLineData
6527f429
DM
1/**\r
2 * {@link Ext.ProgressIndicator} provides a progress indicator for file uploads.\r
3 */\r
4Ext.define('Ext.ProgressIndicator', {\r
5 extend: 'Ext.Container',\r
6\r
7 mixins: ['Ext.mixin.Progressable'],\r
8\r
9 xtype: 'progressindicator',\r
10\r
11 config: {\r
12 baseCls: Ext.baseCSSPrefix + 'progressindicator',\r
13 hidden: true,\r
14 modal: true,\r
15 centered: true,\r
16\r
17 /**\r
18 * @cfg {String/Ext.XTemplate/Object} loadingText\r
19 * This template is used when progress is dynamic (many updates will be received). Template will be passed\r
20 * and object with properties percent and state.\r
21 *\r
22 * If a String or XTemplate is given that text will be used for all states of loading. One can optionally pass in an object\r
23 * with the properties 'upload' and/or 'download' with custom state templates.\r
24 *\r
25 *\r
26 * @accessor\r
27 */\r
28 loadingText: {\r
29 any: 'Loading: {percent}%',\r
30 upload: 'Uploading: {percent}%',\r
31 download: 'Downloading: {percent}%'\r
32 },\r
33\r
34 /**\r
35 * @cfg {String/Object} fallbackText\r
36 * This String is used when progress is not dynamic (only start and end events will be received).\r
37 *\r
38 * If a String is given that text will be used for all states of loading. One can optionally pass in an object\r
39 * with the properties 'upload' and/or 'download' with custom state strings.\r
40 *\r
41 * @accessor\r
42 */\r
43 fallbackText: {\r
44 any: 'Loading',\r
45 upload: 'Uploading',\r
46 download: 'Downloading'\r
47 },\r
48\r
49 /**\r
50 * @cfg {Object} monitoredStates\r
51 * Object with the properties of 'upload' and 'download'. To disable progress monitoring of any state simply set\r
52 * it to false. For example:\r
53 *\r
54 * monitoredStates: {\r
55 * upload:false\r
56 * }\r
57 *\r
58 * @accessor\r
59 */\r
60 monitoredStates: {\r
61 upload: true,\r
62 download: true\r
63 },\r
64\r
65 showAnimation: !Ext.browser.is.AndroidStock ? {\r
66 type: 'slideIn',\r
67 direction: "left",\r
68 duration: 250,\r
69 easing: 'ease-out'\r
70 } : null,\r
71\r
72 hideAnimation: !Ext.browser.is.AndroidStock ? {\r
73 type: 'slideOut',\r
74 direction: "left",\r
75 duration: 250,\r
76 easing: 'ease-in'\r
77 } : null,\r
78\r
79 /**\r
80 * @private\r
81 */\r
82 minProgressOutput: 0,\r
83\r
84 /**\r
85 * @private\r
86 */\r
87 maxProgressOutput: 1,\r
88\r
89 /**\r
90 * @private\r
91 */\r
92 state: null\r
93 },\r
94\r
95 constructor: function() {\r
96 this.emptyTpl = new Ext.XTemplate("");\r
97 this.callParent(arguments);\r
98 },\r
99\r
100 getElementConfig: function() {\r
101 return {\r
102 reference: 'element',\r
103 classList: ['x-container', 'x-unsized'],\r
104 children: [\r
105 {\r
106 reference: 'innerElement',\r
107 className: Ext.baseCSSPrefix + 'progressindicator-inner',\r
108 children: [\r
109 {\r
110 reference: 'progressBarText',\r
111 className: Ext.baseCSSPrefix + 'progressindicator-text'\r
112 },\r
113 {\r
114 reference: 'progressBar',\r
115 className: Ext.baseCSSPrefix + 'progressindicator-bar',\r
116 children: [\r
117 {\r
118 reference: 'progressBarFill',\r
119 className: Ext.baseCSSPrefix + 'progressindicator-bar-fill'\r
120 }\r
121 ]\r
122 }\r
123 ]\r
124 }\r
125 ]\r
126 };\r
127 },\r
128\r
129 onStartProgress: function() {\r
130 if (!this.getParent()) {\r
131 Ext.Viewport.add(this);\r
132 }\r
133 this.show();\r
134 },\r
135\r
136 onEndProgress: function() {\r
137 this.hide();\r
138 },\r
139\r
140 onUpdateProgress: function() {\r
141 this.updateBar();\r
142 },\r
143\r
144 getLoadingText: function() {\r
145 var state = this.getState();\r
146 if (this._loadingText[state]) {\r
147 return this._loadingText[state];\r
148 }\r
149\r
150 if (this._loadingText["any"]) {\r
151 return this._loadingText["any"];\r
152 }\r
153\r
154 return this.emptyTpl;\r
155 },\r
156\r
157 applyLoadingText: function(loadingText) {\r
158 var tpl = {}, property, value;\r
159 if (Ext.isString(loadingText)) {\r
160 tpl = {\r
161 any: new Ext.XTemplate(loadingText)\r
162 }\r
163 } else if (loadingText instanceof Ext.XTemplate) {\r
164 tpl = {\r
165 any: loadingText\r
166 }\r
167 } else {\r
168 for (property in loadingText) {\r
169 value = loadingText[property];\r
170 tpl[property] = new Ext.XTemplate(value);\r
171 }\r
172 }\r
173 if (!tpl.any) {\r
174 tpl.any = this.emptyTpl;\r
175 }\r
176 return tpl;\r
177 },\r
178\r
179 getFallbackText: function() {\r
180 var state = this.getState();\r
181 if (this._fallbackText[state]) {\r
182 return this._fallbackText[state];\r
183 }\r
184\r
185 if(this._fallbackText["any"]) {\r
186 return this._fallbackText["any"];\r
187 }\r
188\r
189 return "";\r
190 },\r
191\r
192 applyFallbackText: function(fallbackText) {\r
193 var obj = {}, property, value;\r
194 if (Ext.isString(fallbackText)) {\r
195 obj = {\r
196 any: fallbackText\r
197 }\r
198 } else {\r
199 for (property in fallbackText) {\r
200 value = fallbackText[property];\r
201 obj[property] = value;\r
202 }\r
203 }\r
204 if (!obj.any) {\r
205 obj.any = this.emptyTpl;\r
206 }\r
207 return obj;\r
208 },\r
209\r
210 updateDynamic: function(value) {\r
211 if (!value) {\r
212 this.progressBarText.setHtml(this.getFallbackText());\r
213 this.progressBar.setWidth("100%");\r
214 } else {\r
215 this.updateBar();\r
216 }\r
217 return value;\r
218 },\r
219\r
220 updateBar: function() {\r
221 var state = this.getState();\r
222 if(this.getMonitoredStates()[state] !== true) {\r
223 this.progressBarText.setHtml(this.getFallbackText());\r
224 this.progressBar.setWidth("100%");\r
225 return;\r
226 }\r
227\r
228 var percent = this.getProgress() * 100;\r
229 if (!Ext.isNumber(percent)) percent = 0;\r
230 this.progressBar.setWidth(percent + "%");\r
231\r
232 var loadingText = this.getLoadingText();\r
233 if (loadingText) {\r
234 this.progressBarText.setHtml(this.getLoadingText().apply({state:state, percent: Math.ceil(percent) || 0}));\r
235 } else {\r
236 this.progressBarText.setHtml('');\r
237 }\r
238 }\r
239})\r
240;\r