ProgressBarPager.js 3.1 KB

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