ProgressBarPager.js 3.3 KB

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