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.

108 lines
2.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * @class Ext.ux.ProgressBarPager
  9. * @extends Object
  10. * Plugin (ptype = 'tabclosemenu') for displaying a progressbar inside of a paging toolbar instead of plain text
  11. *
  12. * @ptype progressbarpager
  13. * @constructor
  14. * Create a new ItemSelector
  15. * @param {Object} config Configuration options
  16. * @xtype itemselector
  17. */
  18. Ext.ux.ProgressBarPager = Ext.extend(Object, {
  19. /**
  20. * @cfg {Integer} progBarWidth
  21. * <p>The default progress bar width. Default is 225.</p>
  22. */
  23. progBarWidth : 225,
  24. /**
  25. * @cfg {String} defaultText
  26. * <p>The text to display while the store is loading. Default is 'Loading...'</p>
  27. */
  28. defaultText : 'Loading...',
  29. /**
  30. * @cfg {Object} defaultAnimCfg
  31. * <p>A {@link Ext.Fx Ext.Fx} configuration object. Default is { duration : 1, easing : 'bounceOut' }.</p>
  32. */
  33. defaultAnimCfg : {
  34. duration : 1,
  35. easing : 'bounceOut'
  36. },
  37. constructor : function(config) {
  38. if (config) {
  39. Ext.apply(this, config);
  40. }
  41. },
  42. //public
  43. init : function (parent) {
  44. if(parent.displayInfo){
  45. this.parent = parent;
  46. var ind = parent.items.indexOf(parent.displayItem);
  47. parent.remove(parent.displayItem, true);
  48. this.progressBar = new Ext.ProgressBar({
  49. text : this.defaultText,
  50. width : this.progBarWidth,
  51. animate : this.defaultAnimCfg
  52. });
  53. parent.displayItem = this.progressBar;
  54. parent.add(parent.displayItem);
  55. parent.doLayout();
  56. Ext.apply(parent, this.parentOverrides);
  57. this.progressBar.on('render', function(pb) {
  58. pb.mon(pb.getEl().applyStyles('cursor:pointer'), 'click', this.handleProgressBarClick, this);
  59. }, this, {single: true});
  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.ceil(position/(displayItem.width/pages));
  72. parent.changePage(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. pgData = this.getPageData(),
  82. pageNum = this.readPage(pgData),
  83. msg = count == 0 ?
  84. this.emptyMsg :
  85. String.format(
  86. this.displayMsg,
  87. this.cursor+1, this.cursor+count, this.store.getTotalCount()
  88. );
  89. pageNum = pgData.activePage; ;
  90. var pct = pageNum / pgData.pages;
  91. this.displayItem.updateProgress(pct, msg, this.animate || this.defaultAnimConfig);
  92. }
  93. }
  94. }
  95. });
  96. Ext.preg('progressbarpager', Ext.ux.ProgressBarPager);