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.
 
 
 
 
 
 

66 lines
2.5 KiB

  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. var uploaders = {};
  23. var upload_frame_count = 0;
  24. //
  25. // parent is the element in which you want to add the upload box
  26. // args - additional hidden arguments
  27. // callback - callback function to be called after upload with file id
  28. //
  29. Uploader = function(parent, args, callback) {
  30. var id = 'frame'+upload_frame_count; upload_frame_count++;
  31. this.callback = callback;
  32. var div = $a(parent, 'div');
  33. div.innerHTML = '<iframe id="'+id+'" name="'+id+'" src="blank.html" \
  34. style="width:0px; height:0px; border:0px"></iframe>';
  35. // upload form
  36. var div = $a(parent,'div');
  37. div.innerHTML = '<form method="POST" enctype="multipart/form-data" action="'+webnotes.request.url+'" target="'+id+'"></form>';
  38. var ul_form = div.childNodes[0];
  39. var f_list = [];
  40. // file data
  41. var inp_fdata = $a_input($a(ul_form,'span'),'file',{name:'filedata'},{marginLeft:'7px'});
  42. if(!('cmd' in args)) { var inp = $a_input($a(ul_form,'span'),'hidden',{name:'cmd'}); inp.value = 'uploadfile'; }
  43. var inp = $a_input($a(ul_form,'span'),'hidden',{name:'uploader_id'}); inp.value = id;
  44. var inp = $a_input($a(ul_form,'span'),'submit',null,{marginLeft:'7px'}); inp.value = 'Upload';
  45. $y(inp,{width:'80px'});
  46. // dt, dn to show
  47. for(var key in args) {
  48. var inp = $a_input($a(ul_form,'span'),'hidden',{name:key}); inp.value = args[key];
  49. }
  50. uploaders[id] = this;
  51. }
  52. function upload_callback(id, fid) {
  53. uploaders[id].callback(fid);
  54. }