ProgressBarPager.js 3.1 KB

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