Web Interface For Lite Argus Control modules
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.

315 lines
12 KiB

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