ProgressBarPager.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-ux-ProgressBarPager-method-constructor'><span id='Ext-ux-ProgressBarPager'>/**
  19. </span></span>* @class Ext.ux.ProgressBarPager
  20. * @extends Object
  21. * Plugin for displaying a progressbar inside of a paging toolbar instead of plain text
  22. * @constructor
  23. * Create a new ProgressBarPager
  24. * @param {Object} config Configuration options
  25. */
  26. Ext.define('Ext.ux.ProgressBarPager', {
  27. requires: ['Ext.ProgressBar'],
  28. <span id='Ext-ux-ProgressBarPager-cfg-width'> /**
  29. </span> * @cfg {Number} width
  30. * &lt;p&gt;The default progress bar width. Default is 225.&lt;/p&gt;
  31. */
  32. width : 225,
  33. <span id='Ext-ux-ProgressBarPager-cfg-defaultText'> /**
  34. </span> * @cfg {String} defaultText
  35. * &lt;p&gt;The text to display while the store is loading. Default is 'Loading...'&lt;/p&gt;
  36. */
  37. defaultText : 'Loading...',
  38. <span id='Ext-ux-ProgressBarPager-cfg-defaultAnimCfg'> /**
  39. </span> * @cfg {Object} defaultAnimCfg
  40. * &lt;p&gt;A {@link Ext.fx.Anim Ext.fx.Anim} configuration object.&lt;/p&gt;
  41. */
  42. defaultAnimCfg : {
  43. duration: 1000,
  44. easing: 'bounceOut'
  45. },
  46. constructor : function(config) {
  47. if (config) {
  48. Ext.apply(this, config);
  49. }
  50. },
  51. //public
  52. init : function (parent) {
  53. var displayItem;
  54. if (parent.displayInfo) {
  55. this.parent = parent;
  56. displayItem = parent.child(&quot;#displayItem&quot;);
  57. if (displayItem) {
  58. parent.remove(displayItem, true);
  59. }
  60. this.progressBar = Ext.create('Ext.ProgressBar', {
  61. text : this.defaultText,
  62. width : this.width,
  63. animate : this.defaultAnimCfg,
  64. style: {
  65. cursor: 'pointer'
  66. },
  67. listeners: {
  68. el: {
  69. scope: this,
  70. click: this.handleProgressBarClick
  71. }
  72. }
  73. });
  74. parent.displayItem = this.progressBar;
  75. parent.add(parent.displayItem);
  76. Ext.apply(parent, this.parentOverrides);
  77. }
  78. },
  79. // private
  80. // This method handles the click for the progress bar
  81. handleProgressBarClick : function(e){
  82. var parent = this.parent,
  83. displayItem = parent.displayItem,
  84. box = this.progressBar.getBox(),
  85. xy = e.getXY(),
  86. position = xy[0]- box.x,
  87. pages = Math.ceil(parent.store.getTotalCount() / parent.pageSize),
  88. newPage = Math.max(Math.ceil(position / (displayItem.width / pages)), 1);
  89. parent.store.loadPage(newPage);
  90. },
  91. // private, overriddes
  92. parentOverrides : {
  93. // private
  94. // This method updates the information via the progress bar.
  95. updateInfo : function(){
  96. if(this.displayItem){
  97. var count = this.store.getCount(),
  98. pageData = this.getPageData(),
  99. message = count === 0 ?
  100. this.emptyMsg :
  101. Ext.String.format(
  102. this.displayMsg,
  103. pageData.fromRecord, pageData.toRecord, this.store.getTotalCount()
  104. ),
  105. percentage = pageData.pageCount &gt; 0 ? (pageData.currentPage / pageData.pageCount) : 0;
  106. this.displayItem.updateProgress(percentage, message, this.animate || this.defaultAnimConfig);
  107. }
  108. }
  109. }
  110. });
  111. </pre>
  112. </body>
  113. </html>