Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.widget.FileInput"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.widget.FileInput"] = true;
3
dojo.provide("dojox.widget.FileInput");
4
dojo.experimental("dojox.widget.FileInput");
5
 
6
dojo.require("dijit.form._FormWidget");
7
dojo.require("dijit._Templated");
8
 
9
dojo.declare("dojox.widget.FileInput",
10
	[dijit.form._FormWidget,dijit._Templated],
11
	{
12
	// summary: A styled input type="file"
13
	//
14
	// description: A input type="file" form widget, with a button for uploading to be styled via css,
15
	//	a cancel button to clear selection, and FormWidget mixin to provide standard dijit.form.Form
16
	//	support (FIXME: maybe not fully implemented)
17
 
18
	// label: String
19
	//	the title text of the "Browse" button
20
	label: "Browse ...",
21
 
22
	// cancelText: String
23
	//	the title of the "Cancel" button
24
	cancelText: "Cancel",
25
 
26
	// name: String
27
	//	ugh, this should be pulled from this.domNode
28
	name: "uploadFile",
29
 
30
	templateString:"<div class=\"dijitFileInput\">\n\t<input id=\"${id}\" class=\"dijitFileInputReal\" type=\"file\" dojoAttachPoint=\"fileInput\" name=\"${name}\" />\n\t<div class=\"dijitFakeInput\">\n\t\t<input class=\"dijitFileInputVisible\" type=\"text\" dojoAttachPoint=\"focusNode, inputNode\" />\n\t\t<span class=\"dijitFileInputText\" dojoAttachPoint=\"titleNode\">${label}</span>\n\t\t<span class=\"dijitFileInputButton\" dojoAttachPoint=\"cancelNode\" \n\t\t\tdojoAttachEvent=\"onclick:_onClick\">${cancelText}</span>\n\t</div>\n</div>\n",
31
 
32
	startup: function(){
33
		// summary: listen for changes on our real file input
34
		this.inherited("startup",arguments);
35
		this._listener = dojo.connect(this.fileInput,"onchange",this,"_matchValue");
36
		this._keyListener = dojo.connect(this.fileInput,"onkeyup",this,"_matchValue");
37
	},
38
 
39
	_matchValue: function(){
40
		// summary: set the content of the upper input based on the semi-hidden file input
41
		this.inputNode.value = this.fileInput.value;
42
		if(this.inputNode.value){
43
			this.cancelNode.style.visibility = "visible";
44
			dojo.fadeIn({ node: this.cancelNode, duration:275 }).play();
45
		}
46
	},
47
 
48
	setLabel: function(/* String */label,/* String? */cssClass){
49
		// summary: method to allow use to change button label
50
		this.titleNode.innerHTML = label;
51
	},
52
 
53
	_onClick: function(/* Event */e){
54
		// summary: on click of cancel button, since we can't clear the input because of
55
		// 	security reasons, we destroy it, and add a new one in it's place.
56
		dojo.disconnect(this._listener);
57
		dojo.disconnect(this._keyListener);
58
		this.domNode.removeChild(this.fileInput);
59
		dojo.fadeOut({ node: this.cancelNode, duration:275 }).play();
60
 
61
		// should we use cloneNode()? can we?
62
		this.fileInput = document.createElement('input');
63
		this.fileInput.setAttribute("type","file");
64
		this.fileInput.setAttribute("id",this.id);
65
		this.fileInput.setAttribute("name",this.name);
66
		dojo.addClass(this.fileInput,"dijitFileInputReal");
67
		this.domNode.appendChild(this.fileInput);
68
 
69
		this._keyListener = dojo.connect(this.fileInput,"onkeyup",this,"_matchValue");
70
		this._listener = dojo.connect(this.fileInput,"onchange",this,"_matchValue");
71
		this.inputNode.value = "";
72
	}
73
 
74
});
75
 
76
}