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 | /*===== |
---|
15 | FormWidget = dijit.form._FormWidget; |
---|
16 | =====*/ |
---|
17 | declare("dojox.form.FileInput", FormWidget, |
---|
18 | { |
---|
19 | // summary: A styled input type="file" |
---|
20 | // |
---|
21 | // description: A input type="file" form widget, with a button for uploading to be styled via css, |
---|
22 | // a cancel button to clear selection, and FormWidget mixin to provide standard dijit.form.Form |
---|
23 | // support (FIXME: maybe not fully implemented) |
---|
24 | |
---|
25 | // label: String |
---|
26 | // the title text of the "Browse" button |
---|
27 | label: "Browse ...", |
---|
28 | |
---|
29 | // cancelText: String |
---|
30 | // the title of the "Cancel" button |
---|
31 | cancelText: "Cancel", |
---|
32 | |
---|
33 | // name: String |
---|
34 | // ugh, this should be pulled from this.domNode |
---|
35 | name: "uploadFile", |
---|
36 | |
---|
37 | templateString: template, |
---|
38 | |
---|
39 | startup: function(){ |
---|
40 | // summary: 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: set the content of the upper input based on the semi-hidden file input |
---|
51 | this.inputNode.value = this.fileInput.value; |
---|
52 | if(this.inputNode.value){ |
---|
53 | this.cancelNode.style.visibility = "visible"; |
---|
54 | fx.fadeIn({ node: this.cancelNode, duration:275 }).play(); |
---|
55 | } |
---|
56 | }, |
---|
57 | |
---|
58 | setLabel: function(/* String */label,/* String? */cssClass){ |
---|
59 | // summary: method to allow use to change button label |
---|
60 | this.titleNode.innerHTML = label; |
---|
61 | }, |
---|
62 | |
---|
63 | reset: function(/* Event */e){ |
---|
64 | // summary: on click of cancel button, since we can't clear the input because of |
---|
65 | // security reasons, we destroy it, and add a new one in it's place. |
---|
66 | this.disconnect(this._listener); |
---|
67 | this.disconnect(this._keyListener); |
---|
68 | if(this.fileInput){ |
---|
69 | this.domNode.removeChild(this.fileInput); |
---|
70 | } |
---|
71 | fx.fadeOut({ node: this.cancelNode, duration:275 }).play(); |
---|
72 | |
---|
73 | // should we use cloneNode()? can we? |
---|
74 | this.fileInput = document.createElement('input'); |
---|
75 | // domAttr.set(this.fileInput,{ |
---|
76 | // "type":"file", "id":this.id, "name": this.name |
---|
77 | //}); |
---|
78 | this.fileInput.setAttribute("type","file"); |
---|
79 | this.fileInput.setAttribute("id", this.id); |
---|
80 | this.fileInput.setAttribute("name", this.name); |
---|
81 | domClass.add(this.fileInput,"dijitFileInputReal"); |
---|
82 | this.domNode.appendChild(this.fileInput); |
---|
83 | |
---|
84 | this._keyListener = this.connect(this.fileInput, "onkeyup", "_matchValue"); |
---|
85 | this._listener = this.connect(this.fileInput, "onchange", "_matchValue"); |
---|
86 | this.inputNode.value = ""; |
---|
87 | } |
---|
88 | |
---|
89 | }); |
---|
90 | |
---|
91 | return dojox.form.FileInput; |
---|
92 | }); |
---|