ProgressBarPager.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 {Integer} 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. constructor : function(config) {
  27. if (config) {
  28. Ext.apply(this, config);
  29. }
  30. },
  31. //public
  32. init : function (parent) {
  33. var displayItem;
  34. if(parent.displayInfo) {
  35. this.parent = parent;
  36. displayItem = parent.child("#displayItem");
  37. if (displayItem) {
  38. parent.remove(displayItem, true);
  39. }
  40. this.progressBar = Ext.create('Ext.ProgressBar', {
  41. text : this.defaultText,
  42. width : this.width,
  43. animate : this.defaultAnimCfg
  44. });
  45. parent.displayItem = this.progressBar;
  46. parent.add(parent.displayItem);
  47. parent.doLayout();
  48. Ext.apply(parent, this.parentOverrides);
  49. this.progressBar.on('render', function(pb) {
  50. pb.mon(pb.getEl().applyStyles('cursor:pointer'), 'click', this.handleProgressBarClick, this);
  51. }, this, {single: true});
  52. }
  53. },
  54. // private
  55. // This method handles the click for the progress bar
  56. handleProgressBarClick : function(e){
  57. var parent = this.parent,
  58. displayItem = parent.displayItem,
  59. box = this.progressBar.getBox(),
  60. xy = e.getXY(),
  61. position = xy[0]- box.x,
  62. pages = Math.ceil(parent.store.getTotalCount()/parent.pageSize),
  63. newpage = Math.ceil(position/(displayItem.width/pages));
  64. parent.store.loadPage(newpage);
  65. },
  66. // private, overriddes
  67. parentOverrides : {
  68. // private
  69. // This method updates the information via the progress bar.
  70. updateInfo : function(){
  71. if(this.displayItem){
  72. var count = this.store.getCount(),
  73. pageData = this.getPageData(),
  74. message = count === 0 ?
  75. this.emptyMsg :
  76. Ext.String.format(
  77. this.displayMsg,
  78. pageData.fromRecord, pageData.toRecord, this.store.getTotalCount()
  79. ),
  80. percentage = pageData.currentPage / pageData.pageCount;
  81. this.displayItem.updateProgress(percentage, message, this.animate || this.defaultAnimConfig);
  82. }
  83. }
  84. }
  85. });