Debian Codegraph @

dojox/form/FileInput.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare",
3 "dojo/_base/kernel",
4 "dojo/_base/fx",
5 "dojo/dom-attr",
6 "dojo/dom-class",
7 "dojo/text!./resources/FileInput.html",
8 "dijit/form/_FormWidget",
9 "dijit/_Templated"
10 ],
11 function(declare, kernel, fx, domAttr, domClass, template, FormWidget, Templated){
12 kernel.experimental("dojox.form.FileInput");
13
14 return declare("dojox.form.FileInput", FormWidget,
15 {
16 // summary:
17 // A styled input type="file"
18 //
19 // description:
20 // A input type="file" form widget, with a button for uploading to be styled via css,
21 // a cancel button to clear selection, and FormWidget mixin to provide standard dijit.form.Form
22 // support (FIXME: maybe not fully implemented)
23
24 // label: String
25 // the title text of the "Browse" button
26 label: "Browse ...",
27
28 // cancelText: String
29 // the title of the "Cancel" button
30 cancelText: "Cancel",
31
32 // name: String
33 // ugh, this should be pulled from this.domNode
34 name: "uploadFile",
35
36 templateString: template,
37
38 startup: function(){
39 // summary:
40 // listen for changes on our real file input
41 this._listener = this.connect(this.fileInput,"onchange","_matchValue");
42 this._keyListener = this.connect(this.fileInput,"onkeyup","_matchValue");
43 },
44
45 //get rid of the this.connect in _FormWidget.postCreate to allow IE to show
46 //the file picker dialog properly
47 postCreate: function(){},
48
49 _matchValue: function(){
50 // summary:
51 // set the content of the upper input based on the semi-hidden file input
52 this.inputNode.value = this.fileInput.value;
53 if(this.inputNode.value){
54 this.cancelNode.style.visibility = "visible";
55 fx.fadeIn({ node: this.cancelNode, duration:275 }).play();
56 }
57 },
58
59 setLabel: function(/*String*/ label, /*String?*/ cssClass){
60 // summary:
61 // method to allow use to change button label
62 this.titleNode.innerHTML = label;
63 },
64
65 reset: function(/*Event*/ e){
66 // summary:
67 // on click of cancel button, since we can't clear the input because of
68 // security reasons, we destroy it, and add a new one in it's place.
69 this.disconnect(this._listener);
70 this.disconnect(this._keyListener);
71 if(this.fileInput){
72 this.domNode.removeChild(this.fileInput);
73 }
74 fx.fadeOut({ node: this.cancelNode, duration:275 }).play();
75
76 // should we use cloneNode()? can we?
77 this.fileInput = document.createElement('input');
78 // domAttr.set(this.fileInput,{
79 // "type":"file", "id":this.id, "name": this.name
80 //});
81 this.fileInput.setAttribute("type","file");
82 this.fileInput.setAttribute("id", this.id);
83 this.fileInput.setAttribute("name", this.name);
84 domClass.add(this.fileInput,"dijitFileInputReal");
85 this.domNode.appendChild(this.fileInput);
86
87 this._keyListener = this.connect(this.fileInput, "onkeyup", "_matchValue");
88 this._listener = this.connect(this.fileInput, "onchange", "_matchValue");
89 this.inputNode.value = "";
90 }
91
92 });
93
94 });