ProgressBar.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*******************************************************************************
  2. * IBM Confidential
  3. *
  4. * OCO Source Materials
  5. *
  6. * A and PM: PD
  7. *
  8. * (c) Copyright IBM Corp. 2014
  9. *
  10. * The source code for this program is not published or otherwise divested of
  11. * its trade secrets, irrespective of what has been deposited with the U.S.
  12. * Copyright Office.
  13. ******************************************************************************/
  14. define([
  15. "dojo/_base/declare",
  16. "dijit/ProgressBar",
  17. "dojo/number",
  18. "dojo/dom-style"
  19. ],function(declare, ProgressBar, number, domStyle){
  20. var PROGRESS_INFINITY = "Infinity";
  21. var UPLOAD_TYPE_HTML5 = "html5";
  22. var UPLOAD_TYPE_FLASH = "flash";
  23. var ProgressBar = declare("pd/widgets/ProgressBar", [ProgressBar], {
  24. maxBytesPerLoad: 0,
  25. previousBytesLoaded: 0,
  26. init: function(/*string*/uploadType) {
  27. this.uploadType = uploadType;
  28. this.pdHide();
  29. this.update({
  30. progress: 0
  31. });
  32. },
  33. pdHide: function() {
  34. domStyle.set(this.domNode, "display", "none");
  35. },
  36. _pdShow: function() {
  37. domStyle.set(this.domNode, "display", "");
  38. },
  39. _isDeterminate: function (){
  40. if (this._getDeterminateMode() && this._supportDeterminate()){
  41. return true;
  42. }
  43. return false;
  44. },
  45. //in case of iframe, you need enforce to indeterminate mode.
  46. _setDeterminateMode: function (/*boolean*/ val){
  47. this.indeterminate = !val;
  48. if (!val){
  49. this.value = PROGRESS_INFINITY;
  50. }
  51. },
  52. _getDeterminateMode: function (){
  53. return !this.indeterminate;
  54. },
  55. _supportDeterminate: function() {
  56. return (this.uploadType == UPLOAD_TYPE_HTML5 || this.uploadType == UPLOAD_TYPE_FLASH);
  57. },
  58. onStageZero: function(){
  59. this._pdShow();
  60. this._setDeterminateMode(this._supportDeterminate());
  61. this.maxBytesPerLoad = 0;
  62. this.previousBytesLoaded = 0;
  63. this.update({
  64. stage: 0,
  65. label: PDMSG.IPT.IDS_IPT_PROGRESS_STAGE_IMPORT
  66. });
  67. },
  68. onStageOne: function(percent) {
  69. this._pdShow();
  70. this.update({
  71. stage: 1,
  72. label: PDMSG.IPT.IDS_IPT_PROGRESS_STAGE_UPLOAD,
  73. progress: percent
  74. });
  75. },
  76. onStageTwo: function(inputLabel) {
  77. var currentLabel = inputLabel || PDMSG.IPT.IDS_IPT_PROGRESS_STAGE_IMPORT;
  78. this._pdShow();
  79. this._setDeterminateMode(false);
  80. this.update({
  81. stage: 2,
  82. label: currentLabel,
  83. progress: 100
  84. });
  85. },
  86. onStageThree: function() {
  87. this._setDeterminateMode(true);
  88. this.update({
  89. stage: 3,
  90. progress: 100,
  91. label: ""
  92. });
  93. var self = this;
  94. setTimeout(function() {
  95. self.pdHide();
  96. self.update({
  97. progress: 0
  98. });
  99. }, 1000);
  100. },
  101. onCancel: function() {
  102. this.pdHide();
  103. this.update({
  104. progress: 0
  105. });
  106. },
  107. report: function(/*float*/percent){
  108. var returnVal = this.label || " ";
  109. //stage 0 or 3 (0% and 100%) will be showed in derterminate mode anyways
  110. if (this._isDeterminate() || (this.stage == undefined || this.stage == 3)){
  111. returnVal +=" " + number.format(percent, {
  112. type: "percent", places: this.places, locale: this.lang });
  113. }
  114. return returnVal;
  115. }
  116. });
  117. return ProgressBar;
  118. });