| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
| 3 | <html> |
| 4 | <head> |
| 5 | <title>dojox.form.FileInput | The Dojo Toolkit</title> |
| 6 | <style type="text/css"> |
| 7 | @import "../../../dojo/resources/dojo.css"; |
| 8 | @import "../../../dijit/themes/dijit.css"; |
| 9 | @import "../../../dijit/tests/css/dijitTests.css"; |
| 10 | @import "../resources/FileInput.css"; |
| 11 | </style> |
| 12 | |
| 13 | <script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="isDebug:true, parseOnLoad: true"></script> |
| 14 | <script type="text/javascript"> |
| 15 | dojo.require("dojox.form.FileInput"); |
| 16 | dojo.require("dojox.form.FileInputAuto"); |
| 17 | dojo.require("dojo.parser"); // scan page for widgets and instantiate them |
| 18 | |
| 19 | var sampleCallback = function(data,ioArgs,widgetRef){ |
| 20 | // this function is fired for every programatic FileUploadAuto |
| 21 | // when the upload is complete. It uses dojo.io.iframe, which |
| 22 | // expects the results to come wrapped in TEXTAREA tags. |
| 23 | // this is IMPORTANT. to utilize FileUploadAuto (or Blind) |
| 24 | // you have to pass your response data in a TEXTAREA tag. |
| 25 | // in our sample file (if you have php5 installed and have |
| 26 | // file uploads enabled) it _should_ return some text in the |
| 27 | // form of valid JSON data, like: |
| 28 | // { status: "success", details: { size: "1024" } } |
| 29 | // you can do whatever. |
| 30 | // |
| 31 | // the ioArgs is the standard ioArgs ref found in all dojo.xhr* methods. |
| 32 | // |
| 33 | // widget is a reference to the calling widget. you can manipulate the widget |
| 34 | // from within this callback function |
| 35 | if(data){ |
| 36 | if(data.status && data.status == "success"){ |
| 37 | widgetRef.overlay.innerHTML = "success!"; |
| 38 | }else{ |
| 39 | widgetRef.overlay.innerHTML = "error? "; |
| 40 | console.log('error',data,ioArgs); |
| 41 | } |
| 42 | }else{ |
| 43 | // debug assist |
| 44 | console.log('ugh?',arguments); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | var i = 0; |
| 49 | function addNewUpload(){ |
| 50 | var node = document.createElement('input'); |
| 51 | dojo.byId('dynamic').appendChild(node); |
| 52 | var widget = new dojox.form.FileInputAuto({ |
| 53 | id: "dynamic"+(++i), |
| 54 | url: "../resources/ReceiveFile.php", |
| 55 | //url:"http://archive.dojotoolkit.org/nightly/checkout/dojox/widget/resources/ReceiveFile.php", |
| 56 | name: "dynamic"+i, |
| 57 | onComplete: sampleCallback |
| 58 | },node); |
| 59 | widget.startup(); |
| 60 | } |
| 61 | |
| 62 | </script> |
| 63 | </head> |
| 64 | <body> |
| 65 | |
| 66 | <h1 class="testTitle">dojox FileInput widget:</h1> |
| 67 | <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> |
| 68 | <p>The API is up for discussion, nor is it known to drop into forms and "just work" yet</p> |
| 69 | <p>FileInputAuto API is up for discussion, as well, though by use of the url="" attrib, you can basically |
| 70 | do all your file-processing server side, and just use the filename sent that remains in the form input</p> |
| 71 | <p>There are two parts. dojo.require("dojox.form.FileInput") for just the base class, or dojo.require("dojox.form.FileInputAuto"); |
| 72 | to provide the Auto Uploading widget (on blur), and the Blind Auto Upload widget.</p> |
| 73 | <p>Both themes are defined in the FileInput.css file, as well as basic styling needed to run</p> |
| 74 | |
| 75 | <h3>A standard file input:</h3> |
| 76 | <input type="file" id="normal" name="inputFile" /> |
| 77 | |
| 78 | <h3>The default dojox.form.FileInput:</h3> |
| 79 | <p> |
| 80 | <input dojoType="dojox.form.FileInput" id="default" name="inputFile" /> |
| 81 | </p> |
| 82 | |
| 83 | <h3>default dojox.form.FileInput, tundra:</h3> |
| 84 | <p class="tundra"> |
| 85 | <input dojoType="dojox.form.FileInput" id="default2" name="inputFile" /> |
| 86 | </p> |
| 87 | |
| 88 | <h3>dojox.form.FileInputAuto, soria theme:</h3> |
| 89 | <p class="soria"> |
| 90 | <input dojoType="dojox.form.FileInputAuto" id="defaultAuto" name="inputFileAuto" url="../resources/ReceiveFile.php" /> |
| 91 | </p> |
| 92 | |
| 93 | <h3>dojox.form.FileInputAuto, claro theme:</h3> |
| 94 | <p class="claro"> |
| 95 | <input dojoType="dojox.form.FileInputAuto" id="claroAuto" name="inputFileAuto" url="../resources/ReceiveFile.php" /> |
| 96 | </p> |
| 97 | |
| 98 | <h3>another one, tundra theme (with callback)</h3> |
| 99 | <p class="tundra"> |
| 100 | <input dojoType="dojox.form.FileInputAuto" id="defaultAuto2" name="inputFileAuto2" url="../resources/ReceiveFile.php" onComplete="sampleCallback"/> |
| 101 | </p> |
| 102 | |
| 103 | <h3>dojox.form.FileInputAuto - tundra theme (with callback) - and onchange triggerEvent</h3> |
| 104 | <p class="tundra"> |
| 105 | <input dojoType="dojox.form.FileInputAuto" id="defaultAuto2onchange" blurDelay="10" name="inputFileAuto2" triggerEvent="onchange" url="../resources/ReceiveFile.php" onComplete="sampleCallback"/> |
| 106 | </p> |
| 107 | |
| 108 | |
| 109 | <h3>a blind auto upload widget, tundra:</h3> |
| 110 | <p class="tundra"> |
| 111 | <input dojoType="dojox.form.FileInputBlind" id="blind1" name="blind1" url="../resources/ReceiveFile.php" /> |
| 112 | </p> |
| 113 | |
| 114 | <h3>dojox.form.FileInputBlind - soria</h3> |
| 115 | <p class="soria"> |
| 116 | <input dojoType="dojox.form.FileInputBlind" id="blind2" name="blind2" label="do my upload" url="../resources/ReceiveFile.php" /> |
| 117 | </p> |
| 118 | |
| 119 | <h3>dynamic, tundra, dojox.form.FileInputAuto:</h3> |
| 120 | <button onclick="addNewUpload()">add new file upload</button> |
| 121 | <br><br> |
| 122 | <div id="dynamic" class="tundra"></div> |
| 123 | |
| 124 | </body> |
| 125 | </html> |