You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.4 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 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
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.ux.ProgressBarPager
  17. * @extends Object
  18. * Plugin (ptype = 'tabclosemenu') for displaying a progressbar inside of a paging toolbar instead of plain text
  19. *
  20. * @ptype progressbarpager
  21. * @constructor
  22. * Create a new ItemSelector
  23. * @param {Object} config Configuration options
  24. * @xtype itemselector
  25. */
  26. Ext.ux.ProgressBarPager = Ext.extend(Object, {
  27. /**
  28. * @cfg {Integer} progBarWidth
  29. * <p>The default progress bar width. Default is 225.</p>
  30. */
  31. progBarWidth : 225,
  32. /**
  33. * @cfg {String} defaultText
  34. * <p>The text to display while the store is loading. Default is 'Loading...'</p>
  35. */
  36. defaultText : 'Loading...',
  37. /**
  38. * @cfg {Object} defaultAnimCfg
  39. * <p>A {@link Ext.Fx Ext.Fx} configuration object. Default is { duration : 1, easing : 'bounceOut' }.</p>
  40. */
  41. defaultAnimCfg : {
  42. duration : 1,
  43. easing : 'bounceOut'
  44. },
  45. constructor : function(config) {
  46. if (config) {
  47. Ext.apply(this, config);
  48. }
  49. },
  50. //public
  51. init : function (parent) {
  52. if(parent.displayInfo){
  53. this.parent = parent;
  54. var ind = parent.items.indexOf(parent.displayItem);
  55. parent.remove(parent.displayItem, true);
  56. this.progressBar = new Ext.ProgressBar({
  57. text : this.defaultText,
  58. width : this.progBarWidth,
  59. animate : this.defaultAnimCfg
  60. });
  61. parent.displayItem = this.progressBar;
  62. parent.add(parent.displayItem);
  63. parent.doLayout();
  64. Ext.apply(parent, this.parentOverrides);
  65. this.progressBar.on('render', function(pb) {
  66. pb.mon(pb.getEl().applyStyles('cursor:pointer'), 'click', this.handleProgressBarClick, this);
  67. }, this, {single: true});
  68. }
  69. },
  70. // private
  71. // This method handles the click for the progress bar
  72. handleProgressBarClick : function(e){
  73. var parent = this.parent,
  74. displayItem = parent.displayItem,
  75. box = this.progressBar.getBox(),
  76. xy = e.getXY(),
  77. position = xy[0]-box.x,
  78. pages = Math.ceil(parent.store.getTotalCount()/parent.pageSize),
  79. newpage = Math.ceil(position/(displayItem.width/pages));
  80. parent.changePage(newpage);
  81. },
  82. // private, overriddes
  83. parentOverrides : {
  84. // private
  85. // This method updates the information via the progress bar.
  86. updateInfo : function(){
  87. if(this.displayItem){
  88. var count = this.store.getCount(),
  89. pgData = this.getPageData(),
  90. pageNum = this.readPage(pgData),
  91. msg = count == 0 ?
  92. this.emptyMsg :
  93. String.format(
  94. this.displayMsg,
  95. this.cursor+1, this.cursor+count, this.store.getTotalCount()
  96. );
  97. pageNum = pgData.activePage; ;
  98. var pct = pageNum / pgData.pages;
  99. this.displayItem.updateProgress(pct, msg, this.animate || this.defaultAnimConfig);
  100. }
  101. }
  102. }
  103. });
  104. Ext.preg('progressbarpager', Ext.ux.ProgressBarPager);