aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/widget/tests/test_FileInput.html
blob: caccd0fd406b0fee55acfb38531abba4b358a534 (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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>dojox.widget.FileInput | The Dojo Toolkit</title>
	<style type="text/css">
		@import "../../../dojo/resources/dojo.css";
		@import "../../../dijit/themes/dijit.css";
		@import "../../../dijit/tests/css/dijitTests.css"; 
		@import "../FileInput/FileInput.css"; 
	</style>

	<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:true, parseOnLoad: true"></script>
	<script type="text/javascript" src="../FileInput.js"></script>
	<script type="text/javascript" src="../FileInputAuto.js"></script>
	<script type="text/javascript">
		// dojo.require("dojox.widget.FileInput"); 
		dojo.require("dojo.parser");	// scan page for widgets and instantiate them
		
		var sampleCallback = function(data,ioArgs,widgetRef){
			// this function is fired for every programatic FileUploadAuto
			// when the upload is complete. It uses dojo.io.iframe, which
			// expects the results to come wrapped in TEXTAREA tags.
			// this is IMPORTANT. to utilize FileUploadAuto (or Blind)
			// you have to pass your respose data in a TEXTAREA tag.
			// in our sample file (if you have php5 installed and have
			// file uploads enabled) it _should_ return some text in the
			// form of valid JSON data, like:
			// { status: "success", details: { size: "1024" } }
			// you can do whatever.
			//
			// the ioArgs is the standard ioArgs ref found in all dojo.xhr* methods.
			//
			// widget is a reference to the calling widget. you can manipulate the widget
			// from within this callback function 
			if(data){
				if(data.status && data.status == "success"){
					widgetRef.overlay.innerHTML = "success!";
				}else{
					widgetRef.overlay.innerHTML = "error? ";
					console.log('error',data,ioArgs);
				}
			}else{
				// debug assist
				console.log('ugh?',arguments);
			}
		}

		var i = 0;
		function addNewUpload(){
			var node = document.createElement('input'); 
			dojo.byId('dynamic').appendChild(node);
			var widget = new dojox.widget.FileInputAuto({
				id: "dynamic"+(++i),
				url: "../FileInput/ReceiveFile.php",
				//url:"http://archive.dojotoolkit.org/nightly/checkout/dojox/widget/FileInput/ReceiveFile.php",
				name: "dynamic"+i,
				onComplete: sampleCallback
			},node);
			widget.startup();
		}

	</script>
</head>
<body>

	<h1 class="testTitle">dojox FileInput widget:</h1>
	<p>This is a prototype of a dojo input type="file" with a FormWidget mixin, to be styled to match tundra and soria themes</p>
	<p>The API is up for discussion, nor is it known to drop into forms and "just work" yet</p>
	<p>FileInputAuto API is up for discussion, as well, though by use of the url="" attrib, you can basically
	do all your file-processing server side, and just use the filename sent that remains in the form input</p>
	<p>There are two parts. dojo.require("dojox.widget.FileInput") for just the base class, or dojo.require("dojox.widget.FileInputAuto"); 
	to provide the Auto Uploading widget (on blur), and the Blind Auto Upload widget.</p>
	<p>Both themes are defined in the FileInput.css file, as well as basic styling needed to run</p>

	<h3>A standard file input:</h3>
	<input type="file" id="normal" name="inputFile" />

	<h3>The default dojox.widget.FileInput:</h3>
	<p>
	<input dojoType="dojox.widget.FileInput" id="default" name="inputFile" />
	</p>

	<h3>default dojox.widget.FileInput, tundra:</h3>
	<p class="tundra">
	<input dojoType="dojox.widget.FileInput" id="default2" name="inputFile" />
	</p>

	<h3>dojox.widget.FileInputAuto, soria theme:</h3>
	<p class="soria">
	<input dojoType="dojox.widget.FileInputAuto" id="defaultAuto" name="inputFileAuto" url="../FileInput/ReceiveFile.php" />
	</p>

	<h3>another one, tundra theme (with callback)</h3>
	<p class="tundra">
	<input dojoType="dojox.widget.FileInputAuto" id="defaultAuto2" name="inputFileAuto2" url="../FileInput/ReceiveFile.php" onComplete="sampleCallback"/>
	</p>

	<h3>a blind auto upload widget, tundra:</h3>
	<p class="tundra">
		<input dojoType="dojox.widget.FileInputBlind" id="blind1" name="blind1" url="../FileInput/ReceiveFile.php" />
	</p>

	<h3>dojox.widget.FileInputBlind - soria</h3>
	<p class="soria">
		<input dojoType="dojox.widget.FileInputBlind" id="blind2" name="blind2" url="../FileInput/ReceiveFile.php" />
	</p>

	<h3>dynamic, tundra, dojox.widget.FileInputAuto:</h3>
	<button onclick="addNewUpload()">add new file upload</button>
	<br><br>
	<div id="dynamic" class="tundra"></div>

</body>
</html>