aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dijit/tests/test_ProgressBar.html
blob: 7df81197312e3becea05b96bb86d4ae987398fdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Dojo Toolkit - ProgressBar test</title>

	<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

	<style type="text/css">
		@import "../../dojo/resources/dojo.css";
		@import "css/dijitTests.css";
		body {
			margin: 1em;
		}
		.smallred .dijitProgressBarTile {
			background:red;
		}
		.smallred .dijitProgressBarLabel {
			display:none;
		}
	</style>

	<script type="text/javascript" src="../../dojo/dojo.js"
		djConfig="parseOnLoad: true, isDebug: true"></script>
	<script type="text/javascript" src="_testCommon.js"></script>

	<script type="text/javascript">
		dojo.require("dijit.ProgressBar");
		dojo.require("dojo.parser");	// scan page for widgets
		dojo.require("dojo.string");

		dojo.addOnLoad(go);

		function go(){
			//TODO: it's a little strange that id must be specified again?	
			var theBar = new dijit.ProgressBar({id: "testBar", width: 400, annotate: true, maximum: 256, duration: 2000,
				report:function(percent){
					return dojo.string.substitute("${0} out of ${1} max chars", [this.progress, this.maximum]);
				}
			}, dojo.byId("testBar"));

			dojo.byId("test").value="";
			dojo.byId("progressValue").focus();
			dojo.byId("progressValue").value = dijit.byId("setTestBar").progress;
			dojo.byId("maximum").value = dijit.byId("setTestBar").maximum;
			dojo.connect(dojo.byId("test"), "onkeyup", null, keyUpHandler);
			dojo.connect(dojo.byId("set"), "onclick", null, setParameters);
			dojo.connect(dojo.byId("startTimer"), "onclick", null,
				function(){ remoteProgress(dijit.byId("timerBar")); } );

			function indeterminateSetter(id, value){
				return function(){
					dijit.byId(id).update({'indeterminate': value});
				}
			}
			dojo.connect(dojo.byId("setIndeterminate1True"), "onclick", null,
				indeterminateSetter("indeterminateBar1", true));
			dojo.connect(dojo.byId("setIndeterminate1False"), "onclick", null,
				indeterminateSetter("indeterminateBar1", false));
			dojo.connect(dojo.byId("setIndeterminate2True"), "onclick", null,
				indeterminateSetter("indeterminateBar2", true));
			dojo.connect(dojo.byId("setIndeterminate2False"), "onclick", null,
				indeterminateSetter("indeterminateBar2", false));
		}

		// An example of polling on a separate (heartbeat) server thread.  This is useful when the progress
		// is entirely server bound and there is no existing interaction with the server to determine status.

		// We don't have a server to run against, but a simple heartbeat implementation might look something
		// like this:

		// function getProgressReport(){
		//	var dataSource = "http://dojotoolkit.org";
		//	return dojo.xhrGet({url: dataSource, handleAs: "json", content: {key: "progress"}});
		// }

		// Instead, we'll just tick off intervals of 10

		var fakeProgress = 0;
		function getProgressReport(){
			var deferred = new dojo.Deferred();
			fakeProgress = Math.min(fakeProgress + 10, 100);
			deferred.callback(fakeProgress+"%");
			return deferred;
		}

		function remoteProgress(bar){
			var _timer = setInterval(function(){
				var report = getProgressReport();
				report.addCallback(function(response){
					bar.update({progress: response});
					if(response == "100%"){
						clearInterval(_timer);
						_timer = null;
						return;
					}
				});
			}, 3000); // on 3 second intervals
		}

		function setParameters(){
			dijit.byId("setTestBar").update({maximum: dojo.byId("maximum").value, progress: dojo.byId("progressValue").value});
		}

		function keyUpHandler(){
			dijit.byId("testBar").update({progress:dojo.byId("test").value.length});
			dijit.byId("testBarInt").update({progress:dojo.byId("test").value.length});
			dijit.byId("smallTestBar").update({progress:dojo.byId("test").value.length});
		}
	</script>
</head>
<body>

	<h1 class="testTitle">Dijit ProgressBar Tests</h1>

	<h3>Test 1</h3>
	Progress Value <input type="text" name="progressValue" id="progressValue" />
	<br>
	Max Progress Value <input type="text" name="maximum" id="maximum" />
	<br>
	<input type="button" name="set" id="set" value="set!" />
	<br>
	<div style="width:400px" annotate="true"
		maximum="200" id="setTestBar" progress="20" dojoType="dijit.ProgressBar"></div>

	<h3>Test 2</h3>
	Write here: <input type="text" value="" name="test" maxLength="256" id="test" style="width:300"/>
	<br />
	<br />
	<div id="testBar" style='width:300px'></div>		
	<br />
	Small, without text and background image:
	<br />
	<div style="width:400px; height:10px" class="smallred"
		maximum="256" id="smallTestBar" dojoType="dijit.ProgressBar"></div>		
	<br />
	Show decimal place:
	<div places="1" style="width:400px" annotate="true"
		maximum="256" id="testBarInt" dojoType="dijit.ProgressBar"></div>

	<h3>Test 3</h3>
	No explicit maximum (both 50%)
	<div style="width:400px" annotate="true"
		id="implied1" progress="50" dojoType="dijit.ProgressBar"></div>		
	<br />
	<div style="width:400px" annotate="true"
		id="implied2" progress="50%" dojoType="dijit.ProgressBar"></div>

	<h3>Test 4</h3>
	<input type="button" name="startTimer" id="startTimer" value="Start Timer" />
	<div style="width:400px" id="timerBar" annotate="true"
		maximum="100" progress="0" dojoType="dijit.ProgressBar"></div>

	<h3>Test 5 - indeterminate progess</h3>
	<input type="button" name="setIndeterminate1True" id="setIndeterminate1True" value="Make Indeterminate" />
	<input type="button" name="setIndeterminate1False" id="setIndeterminate1False" value="Make Determinate" />
	<div style="width:400px" indeterminate="true" id="indeterminateBar1"
		dojoType="dijit.ProgressBar"></div>
	<input type="button" name="setIndeterminate2True" id="setIndeterminate2True" value="Make Indeterminate" />
	<input type="button" name="setIndeterminate2False" id="setIndeterminate2False" value="Make Determinate" />
	<div style="width:400px" progress="50" id="indeterminateBar2"
		dojoType="dijit.ProgressBar"></div>

</body>
</html>