You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

upload.js 942 B

13 years ago
12345678910111213141516171819202122232425262728293031323334
  1. // parent, args, callback
  2. wn.upload = {
  3. make: function(opts) {
  4. var id = wn.dom.set_unique_id();
  5. $(opts.parent).append(repl('<iframe id="%(id)s" name="%(id)s" src="blank.html" \
  6. style="width:0px; height:0px; border:0px"></iframe>\
  7. <form method="POST" enctype="multipart/form-data" \
  8. action="%(action)s" target="%(id)s">\
  9. <input type="file" name="filedata" /><br>\
  10. <input type="submit" class="btn btn-small" value="Upload" />\
  11. </form>', {
  12. id: id,
  13. action: wn.request.url
  14. }));
  15. opts.args.cmd = 'uploadfile';
  16. opts.args._id = id;
  17. // add request parameters
  18. for(key in opts.args) {
  19. if(opts.args[key]) {
  20. $('<input type="hidden">')
  21. .attr('name', key)
  22. .attr('value', opts.args[key])
  23. .appendTo($(opts.parent).find('form'));
  24. }
  25. }
  26. $('#' + id).get(0).callback = opts.callback
  27. },
  28. callback: function(id, file_id, args) {
  29. $('#' + id).get(0).callback(file_id, args);
  30. }
  31. }