test_ProgressBar.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <title>Dojo Toolkit - ProgressBar test</title>
  6. <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  7. <style type="text/css">
  8. @import "../../dojo/resources/dojo.css";
  9. @import "css/dijitTests.css";
  10. body {
  11. margin: 1em;
  12. }
  13. .smallred .dijitProgressBarTile {
  14. background:red;
  15. }
  16. .smallred .dijitProgressBarLabel {
  17. display:none;
  18. }
  19. </style>
  20. <script type="text/javascript" src="../../dojo/dojo.js"
  21. djConfig="parseOnLoad: true, isDebug: true"></script>
  22. <script type="text/javascript" src="_testCommon.js"></script>
  23. <script type="text/javascript">
  24. dojo.require("dijit.ProgressBar");
  25. dojo.require("dojo.parser"); // scan page for widgets
  26. dojo.require("dojo.string");
  27. </script>
  28. <script type="text/javascript">
  29. dojo.addOnLoad(go);
  30. function go(){
  31. //TODO: it's a little strange that id must be specified again?
  32. var theBar = new dijit.ProgressBar({id: "testBar", width: 400, annotate: true, maximum: 256, duration: 2000,
  33. report:function(percent){
  34. return dojo.string.substitute("${0} out of ${1} max chars", [this.progress, this.maximum]);
  35. }
  36. }, dojo.byId("testBar"));
  37. dojo.byId("test").value="";
  38. dojo.byId("progressValue").focus();
  39. dojo.byId("progressValue").value = dijit.byId("setTestBar").progress;
  40. dojo.byId("maximum").value = dijit.byId("setTestBar").maximum;
  41. dojo.connect(dojo.byId("test"), "onkeyup", null, keyUpHandler);
  42. dojo.connect(dojo.byId("set"), "onclick", null, setParameters);
  43. dojo.connect(dojo.byId("startTimer"), "onclick", null,
  44. function(){ remoteProgress(dijit.byId("timerBar")); } );
  45. function indeterminateSetter(id, value){
  46. return function(){
  47. dijit.byId(id).update({'indeterminate': value});
  48. }
  49. }
  50. dojo.connect(dojo.byId("setIndeterminate1True"), "onclick", null,
  51. indeterminateSetter("indeterminateBar1", true));
  52. dojo.connect(dojo.byId("setIndeterminate1False"), "onclick", null,
  53. indeterminateSetter("indeterminateBar1", false));
  54. dojo.connect(dojo.byId("setIndeterminate2True"), "onclick", null,
  55. indeterminateSetter("indeterminateBar2", true));
  56. dojo.connect(dojo.byId("setIndeterminate2False"), "onclick", null,
  57. indeterminateSetter("indeterminateBar2", false));
  58. }
  59. // An example of polling on a separate (heartbeat) server thread. This is useful when the progress
  60. // is entirely server bound and there is no existing interaction with the server to determine status.
  61. // We don't have a server to run against, but a simple heartbeat implementation might look something
  62. // like this:
  63. // function getProgressReport(){
  64. // var dataSource = "http://dojotoolkit.org";
  65. // return dojo.xhrGet({url: dataSource, handleAs: "json", content: {key: "progress"}});
  66. // }
  67. // Instead, we'll just tick off intervals of 10
  68. var fakeProgress = 0;
  69. function getProgressReport(){
  70. var deferred = new dojo.Deferred();
  71. fakeProgress = Math.min(fakeProgress + 10, 100);
  72. deferred.callback(fakeProgress+"%");
  73. return deferred;
  74. }
  75. function remoteProgress(bar){
  76. var _timer = setInterval(function(){
  77. var report = getProgressReport();
  78. report.addCallback(function(response){
  79. bar.update({progress: response});
  80. if(response == "100%"){
  81. clearInterval(_timer);
  82. _timer = null;
  83. return;
  84. }
  85. });
  86. }, 3000); // on 3 second intervals
  87. }
  88. function setParameters(){
  89. dijit.byId("setTestBar").update({maximum: dojo.byId("maximum").value, progress: dojo.byId("progressValue").value});
  90. }
  91. function keyUpHandler(){
  92. dijit.byId("testBar").update({progress:dojo.byId("test").value.length});
  93. dijit.byId("testBarInt").update({progress:dojo.byId("test").value.length});
  94. dijit.byId("smallTestBar").update({progress:dojo.byId("test").value.length});
  95. }
  96. </script>
  97. </head>
  98. <body class="tundra">
  99. <h1 class="testTitle">Dijit ProgressBar Tests</h1>
  100. <h3>Test 1</h3>
  101. Progress Value <input type="text" name="progressValue" id="progressValue" />
  102. <br>
  103. Max Progress Value <input type="text" name="maximum" id="maximum" />
  104. <br>
  105. <input type="button" name="set" id="set" value="set!" />
  106. <br>
  107. <div style="width:400px" annotate="true"
  108. maximum="200" id="setTestBar" progress="20" dojoType="dijit.ProgressBar"></div>
  109. <h3>Test 2</h3>
  110. Write here: <input type="text" value="" name="test" maxLength="256" id="test" style="width:300"/>
  111. <br />
  112. <br />
  113. <div id="testBar" style='width:300px'></div>
  114. <br />
  115. Small, without text and background image:
  116. <br />
  117. <div style="width:400px; height:10px" class="smallred"
  118. maximum="256" id="smallTestBar" dojoType="dijit.ProgressBar"></div>
  119. <br />
  120. Show decimal place:
  121. <div places="1" style="width:400px" annotate="true"
  122. maximum="256" id="testBarInt" dojoType="dijit.ProgressBar"></div>
  123. <h3>Test 3</h3>
  124. No explicit maximum (both 50%)
  125. <div style="width:400px" annotate="true"
  126. id="implied1" progress="50" dojoType="dijit.ProgressBar"></div>
  127. <br />
  128. <div style="width:400px" annotate="true"
  129. id="implied2" progress="50%" dojoType="dijit.ProgressBar"></div>
  130. <h3>Test 4</h3>
  131. <input type="button" name="startTimer" id="startTimer" value="Start Timer" />
  132. <div style="width:400px" id="timerBar" annotate="true"
  133. maximum="100" progress="0" dojoType="dijit.ProgressBar"></div>
  134. <h3>Test 5 - indeterminate progess</h3>
  135. <input type="button" name="setIndeterminate1True" id="setIndeterminate1True" value="Make Indeterminate" />
  136. <input type="button" name="setIndeterminate1False" id="setIndeterminate1False" value="Make Determinate" />
  137. <div style="width:400px" indeterminate="true" id="indeterminateBar1"
  138. dojoType="dijit.ProgressBar"></div>
  139. <input type="button" name="setIndeterminate2True" id="setIndeterminate2True" value="Make Indeterminate" />
  140. <input type="button" name="setIndeterminate2False" id="setIndeterminate2False" value="Make Determinate" />
  141. <div style="width:400px" progress="50" id="indeterminateBar2"
  142. dojoType="dijit.ProgressBar"></div>
  143. </body>
  144. </html>