ProgressBarPager.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. /**
  10. * @class Ext.ux.ProgressBarPager
  11. * @extends Object
  12. * Plugin for displaying a progressbar inside of a paging toolbar instead of plain text
  13. * @constructor
  14. * Create a new ItemSelector
  15. * @param {Object} config Configuration options
  16. */
  17. Ext.define('Ext.ux.ProgressBarPager', {
  18. extend: 'Object',
  19. requires: ['Ext.ProgressBar'],
  20. /**
  21. * @cfg {Integer} width
  22. * <p>The default progress bar width. Default is 225.</p>
  23. */
  24. width : 225,
  25. /**
  26. * @cfg {String} defaultText
  27. * <p>The text to display while the store is loading. Default is 'Loading...'</p>
  28. */
  29. defaultText : 'Loading...',
  30. /**
  31. * @cfg {Object} defaultAnimCfg
  32. * <p>A {@link Ext.fx.Anim Ext.fx.Anim} configuration object.</p>
  33. */
  34. defaultAnimCfg : {
  35. duration: 1000,
  36. easing: 'bounceOut'
  37. },
  38. constructor : function(config) {
  39. if (config) {
  40. Ext.apply(this, config);
  41. }
  42. },
  43. //public
  44. init : function (parent) {
  45. var displayItem;
  46. if(parent.displayInfo) {
  47. this.parent = parent;
  48. displayItem = parent.child("#displayItem");
  49. if (displayItem) {
  50. parent.remove(displayItem, true);
  51. }
  52. this.progressBar = Ext.create('Ext.ProgressBar', {
  53. text : this.defaultText,
  54. width : this.width,
  55. animate : this.defaultAnimCfg
  56. });
  57. parent.displayItem = this.progressBar;
  58. parent.add(parent.displayItem);
  59. parent.doLayout();
  60. Ext.apply(parent, this.parentOverrides);
  61. this.progressBar.on('render', function(pb) {
  62. pb.mon(pb.getEl().applyStyles('cursor:pointer'), 'click', this.handleProgressBarClick, this);
  63. }, this, {single: true});
  64. }
  65. },
  66. // private
  67. // This method handles the click for the progress bar
  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. pages = Math.ceil(parent.store.getTotalCount()/parent.pageSize),
  75. newpage = Math.ceil(position/(displayItem.width/pages));
  76. parent.store.loadPage(newpage);
  77. },
  78. // private, overriddes
  79. parentOverrides : {
  80. // private
  81. // This method updates the information via the progress bar.
  82. updateInfo : function(){
  83. if(this.displayItem){
  84. var count = this.store.getCount(),
  85. pageData = this.getPageData(),
  86. message = count === 0 ?
  87. this.emptyMsg :
  88. Ext.String.format(
  89. this.displayMsg,
  90. pageData.fromRecord, pageData.toRecord, this.store.getTotalCount()
  91. ),
  92. percentage = pageData.pageCount > 0 ? (pageData.currentPage / pageData.pageCount) : 0;
  93. this.displayItem.updateProgress(percentage, message, this.animate || this.defaultAnimConfig);
  94. }
  95. }
  96. }
  97. });