source: Dev/branches/rest-dojo-ui/client/dojox/form/FileInput.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.8 KB
Line 
1define([
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],
11function(declare, kernel, fx, domAttr, domClass, template, FormWidget, Templated){
12kernel.experimental("dojox.form.FileInput");
13
14        /*=====
15                FormWidget = dijit.form._FormWidget;
16        =====*/
17declare("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
91return dojox.form.FileInput;
92});
Note: See TracBrowser for help on using the repository browser.