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.

319 lines
14 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-ProgressBar-cfg-id'><span id='Ext-ProgressBar-cfg-textEl'><span id='Ext-ProgressBar-cfg-text'><span id='Ext-ProgressBar-cfg-value'><span id='Ext-ProgressBar'>/**
  19. </span></span></span></span></span> * @class Ext.ProgressBar
  20. * @extends Ext.BoxComponent
  21. * &lt;p&gt;An updateable progress bar component. The progress bar supports two different modes: manual and automatic.&lt;/p&gt;
  22. * &lt;p&gt;In manual mode, you are responsible for showing, updating (via {@link #updateProgress}) and clearing the
  23. * progress bar as needed from your own code. This method is most appropriate when you want to show progress
  24. * throughout an operation that has predictable points of interest at which you can update the control.&lt;/p&gt;
  25. * &lt;p&gt;In automatic mode, you simply call {@link #wait} and let the progress bar run indefinitely, only clearing it
  26. * once the operation is complete. You can optionally have the progress bar wait for a specific amount of time
  27. * and then clear itself. Automatic mode is most appropriate for timed operations or asynchronous operations in
  28. * which you have no need for indicating intermediate progress.&lt;/p&gt;
  29. * @cfg {Float} value A floating point value between 0 and 1 (e.g., .5, defaults to 0)
  30. * @cfg {String} text The progress bar text (defaults to '')
  31. * @cfg {Mixed} textEl The element to render the progress text to (defaults to the progress
  32. * bar's internal text element)
  33. * @cfg {String} id The progress bar element's id (defaults to an auto-generated id)
  34. * @xtype progress
  35. */
  36. Ext.ProgressBar = Ext.extend(Ext.BoxComponent, {
  37. <span id='Ext-ProgressBar-cfg-baseCls'> /**
  38. </span> * @cfg {String} baseCls
  39. * The base CSS class to apply to the progress bar's wrapper element (defaults to 'x-progress')
  40. */
  41. baseCls : 'x-progress',
  42. <span id='Ext-ProgressBar-cfg-animate'> /**
  43. </span> * @cfg {Boolean} animate
  44. * True to animate the progress bar during transitions (defaults to false)
  45. */
  46. animate : false,
  47. <span id='Ext-ProgressBar-property-waitTimer'> // private
  48. </span> waitTimer : null,
  49. <span id='Ext-ProgressBar-method-initComponent'> // private
  50. </span> initComponent : function(){
  51. Ext.ProgressBar.superclass.initComponent.call(this);
  52. this.addEvents(
  53. <span id='Ext-ProgressBar-event-update'> /**
  54. </span> * @event update
  55. * Fires after each update interval
  56. * @param {Ext.ProgressBar} this
  57. * @param {Number} value The current progress value
  58. * @param {String} text The current progress text
  59. */
  60. &quot;update&quot;
  61. );
  62. },
  63. <span id='Ext-ProgressBar-method-onRender'> // private
  64. </span> onRender : function(ct, position){
  65. var tpl = new Ext.Template(
  66. '&lt;div class=&quot;{cls}-wrap&quot;&gt;',
  67. '&lt;div class=&quot;{cls}-inner&quot;&gt;',
  68. '&lt;div class=&quot;{cls}-bar&quot;&gt;',
  69. '&lt;div class=&quot;{cls}-text&quot;&gt;',
  70. '&lt;div&gt;&amp;#160;&lt;/div&gt;',
  71. '&lt;/div&gt;',
  72. '&lt;/div&gt;',
  73. '&lt;div class=&quot;{cls}-text {cls}-text-back&quot;&gt;',
  74. '&lt;div&gt;&amp;#160;&lt;/div&gt;',
  75. '&lt;/div&gt;',
  76. '&lt;/div&gt;',
  77. '&lt;/div&gt;'
  78. );
  79. this.el = position ? tpl.insertBefore(position, {cls: this.baseCls}, true)
  80. : tpl.append(ct, {cls: this.baseCls}, true);
  81. if(this.id){
  82. this.el.dom.id = this.id;
  83. }
  84. var inner = this.el.dom.firstChild;
  85. this.progressBar = Ext.get(inner.firstChild);
  86. if(this.textEl){
  87. //use an external text el
  88. this.textEl = Ext.get(this.textEl);
  89. delete this.textTopEl;
  90. }else{
  91. //setup our internal layered text els
  92. this.textTopEl = Ext.get(this.progressBar.dom.firstChild);
  93. var textBackEl = Ext.get(inner.childNodes[1]);
  94. this.textTopEl.setStyle(&quot;z-index&quot;, 99).addClass('x-hidden');
  95. this.textEl = new Ext.CompositeElement([this.textTopEl.dom.firstChild, textBackEl.dom.firstChild]);
  96. this.textEl.setWidth(inner.offsetWidth);
  97. }
  98. this.progressBar.setHeight(inner.offsetHeight);
  99. },
  100. <span id='Ext-ProgressBar-method-afterRender'> // private
  101. </span> afterRender : function(){
  102. Ext.ProgressBar.superclass.afterRender.call(this);
  103. if(this.value){
  104. this.updateProgress(this.value, this.text);
  105. }else{
  106. this.updateText(this.text);
  107. }
  108. },
  109. <span id='Ext-ProgressBar-method-updateProgress'> /**
  110. </span> * Updates the progress bar value, and optionally its text. If the text argument is not specified,
  111. * any existing text value will be unchanged. To blank out existing text, pass ''. Note that even
  112. * if the progress bar value exceeds 1, it will never automatically reset -- you are responsible for
  113. * determining when the progress is complete and calling {@link #reset} to clear and/or hide the control.
  114. * @param {Float} value (optional) A floating point value between 0 and 1 (e.g., .5, defaults to 0)
  115. * @param {String} text (optional) The string to display in the progress text element (defaults to '')
  116. * @param {Boolean} animate (optional) Whether to animate the transition of the progress bar. If this value is
  117. * not specified, the default for the class is used (default to false)
  118. * @return {Ext.ProgressBar} this
  119. */
  120. updateProgress : function(value, text, animate){
  121. this.value = value || 0;
  122. if(text){
  123. this.updateText(text);
  124. }
  125. if(this.rendered &amp;&amp; !this.isDestroyed){
  126. var w = Math.floor(value*this.el.dom.firstChild.offsetWidth);
  127. this.progressBar.setWidth(w, animate === true || (animate !== false &amp;&amp; this.animate));
  128. if(this.textTopEl){
  129. //textTopEl should be the same width as the bar so overflow will clip as the bar moves
  130. this.textTopEl.removeClass('x-hidden').setWidth(w);
  131. }
  132. }
  133. this.fireEvent('update', this, value, text);
  134. return this;
  135. },
  136. <span id='Ext-ProgressBar-method-wait'> /**
  137. </span> * Initiates an auto-updating progress bar. A duration can be specified, in which case the progress
  138. * bar will automatically reset after a fixed amount of time and optionally call a callback function
  139. * if specified. If no duration is passed in, then the progress bar will run indefinitely and must
  140. * be manually cleared by calling {@link #reset}. The wait method accepts a config object with
  141. * the following properties:
  142. * &lt;pre&gt;
  143. Property Type Description
  144. ---------- ------------ ----------------------------------------------------------------------
  145. duration Number The length of time in milliseconds that the progress bar should
  146. run before resetting itself (defaults to undefined, in which case it
  147. will run indefinitely until reset is called)
  148. interval Number The length of time in milliseconds between each progress update
  149. (defaults to 1000 ms)
  150. animate Boolean Whether to animate the transition of the progress bar. If this value is
  151. not specified, the default for the class is used.
  152. increment Number The number of progress update segments to display within the progress
  153. bar (defaults to 10). If the bar reaches the end and is still
  154. updating, it will automatically wrap back to the beginning.
  155. text String Optional text to display in the progress bar element (defaults to '').
  156. fn Function A callback function to execute after the progress bar finishes auto-
  157. updating. The function will be called with no arguments. This function
  158. will be ignored if duration is not specified since in that case the
  159. progress bar can only be stopped programmatically, so any required function
  160. should be called by the same code after it resets the progress bar.
  161. scope Object The scope that is passed to the callback function (only applies when
  162. duration and fn are both passed).
  163. &lt;/pre&gt;
  164. *
  165. * Example usage:
  166. * &lt;pre&gt;&lt;code&gt;
  167. var p = new Ext.ProgressBar({
  168. renderTo: 'my-el'
  169. });
  170. //Wait for 5 seconds, then update the status el (progress bar will auto-reset)
  171. p.wait({
  172. interval: 100, //bar will move fast!
  173. duration: 5000,
  174. increment: 15,
  175. text: 'Updating...',
  176. scope: this,
  177. fn: function(){
  178. Ext.fly('status').update('Done!');
  179. }
  180. });
  181. //Or update indefinitely until some async action completes, then reset manually
  182. p.wait();
  183. myAction.on('complete', function(){
  184. p.reset();
  185. Ext.fly('status').update('Done!');
  186. });
  187. &lt;/code&gt;&lt;/pre&gt;
  188. * @param {Object} config (optional) Configuration options
  189. * @return {Ext.ProgressBar} this
  190. */
  191. wait : function(o){
  192. if(!this.waitTimer){
  193. var scope = this;
  194. o = o || {};
  195. this.updateText(o.text);
  196. this.waitTimer = Ext.TaskMgr.start({
  197. run: function(i){
  198. var inc = o.increment || 10;
  199. i -= 1;
  200. this.updateProgress(((((i+inc)%inc)+1)*(100/inc))*0.01, null, o.animate);
  201. },
  202. interval: o.interval || 1000,
  203. duration: o.duration,
  204. onStop: function(){
  205. if(o.fn){
  206. o.fn.apply(o.scope || this);
  207. }
  208. this.reset();
  209. },
  210. scope: scope
  211. });
  212. }
  213. return this;
  214. },
  215. <span id='Ext-ProgressBar-method-isWaiting'> /**
  216. </span> * Returns true if the progress bar is currently in a {@link #wait} operation
  217. * @return {Boolean} True if waiting, else false
  218. */
  219. isWaiting : function(){
  220. return this.waitTimer !== null;
  221. },
  222. <span id='Ext-ProgressBar-method-updateText'> /**
  223. </span> * Updates the progress bar text. If specified, textEl will be updated, otherwise the progress
  224. * bar itself will display the updated text.
  225. * @param {String} text (optional) The string to display in the progress text element (defaults to '')
  226. * @return {Ext.ProgressBar} this
  227. */
  228. updateText : function(text){
  229. this.text = text || '&amp;#160;';
  230. if(this.rendered){
  231. this.textEl.update(this.text);
  232. }
  233. return this;
  234. },
  235. <span id='Ext-ProgressBar-method-syncProgressBar'> /**
  236. </span> * Synchronizes the inner bar width to the proper proportion of the total componet width based
  237. * on the current progress {@link #value}. This will be called automatically when the ProgressBar
  238. * is resized by a layout, but if it is rendered auto width, this method can be called from
  239. * another resize handler to sync the ProgressBar if necessary.
  240. */
  241. syncProgressBar : function(){
  242. if(this.value){
  243. this.updateProgress(this.value, this.text);
  244. }
  245. return this;
  246. },
  247. <span id='Ext-ProgressBar-method-setSize'> /**
  248. </span> * Sets the size of the progress bar.
  249. * @param {Number} width The new width in pixels
  250. * @param {Number} height The new height in pixels
  251. * @return {Ext.ProgressBar} this
  252. */
  253. setSize : function(w, h){
  254. Ext.ProgressBar.superclass.setSize.call(this, w, h);
  255. if(this.textTopEl){
  256. var inner = this.el.dom.firstChild;
  257. this.textEl.setSize(inner.offsetWidth, inner.offsetHeight);
  258. }
  259. this.syncProgressBar();
  260. return this;
  261. },
  262. <span id='Ext-ProgressBar-method-reset'> /**
  263. </span> * Resets the progress bar value to 0 and text to empty string. If hide = true, the progress
  264. * bar will also be hidden (using the {@link #hideMode} property internally).
  265. * @param {Boolean} hide (optional) True to hide the progress bar (defaults to false)
  266. * @return {Ext.ProgressBar} this
  267. */
  268. reset : function(hide){
  269. this.updateProgress(0);
  270. if(this.textTopEl){
  271. this.textTopEl.addClass('x-hidden');
  272. }
  273. this.clearTimer();
  274. if(hide === true){
  275. this.hide();
  276. }
  277. return this;
  278. },
  279. <span id='Ext-ProgressBar-method-clearTimer'> // private
  280. </span> clearTimer : function(){
  281. if(this.waitTimer){
  282. this.waitTimer.onStop = null; //prevent recursion
  283. Ext.TaskMgr.stop(this.waitTimer);
  284. this.waitTimer = null;
  285. }
  286. },
  287. <span id='Ext-ProgressBar-method-onDestroy'> onDestroy: function(){
  288. </span> this.clearTimer();
  289. if(this.rendered){
  290. if(this.textEl.isComposite){
  291. this.textEl.clear();
  292. }
  293. Ext.destroyMembers(this, 'textEl', 'progressBar', 'textTopEl');
  294. }
  295. Ext.ProgressBar.superclass.onDestroy.call(this);
  296. }
  297. });
  298. Ext.reg('progress', Ext.ProgressBar);</pre>
  299. </body>
  300. </html>