test_FileInput.html 4.4 KB

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