Uploader.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*******************************************************************************
  2. * IBM Confidential
  3. *
  4. * OCO Source Materials
  5. *
  6. * A and PM: PD
  7. *
  8. * (c) Copyright IBM Corp. 2014, 2015
  9. *
  10. * The source code for this program is not published or otherwise divested of
  11. * its trade secrets, irrespective of what has been deposited with the U.S.
  12. * Copyright Office.
  13. ******************************************************************************/
  14. define([
  15. "dojo/_base/declare",
  16. "dojox/form/Uploader",
  17. "pd/widgets/uploader/HTML5",
  18. "pd/widgets/uploader/IFrame",
  19. "dojo/dom-form",
  20. "dojo/dom-attr"
  21. ],function(declare, dojoUploader, HTML5, IFrame, domForm, domAttr){
  22. var INPUT_BOX_SIZE = 43;
  23. var Uploader = declare("pd/widgets/Uploader", [dojoUploader, HTML5, IFrame], {
  24. handleAs: "html",
  25. postMixInProperties: function(){
  26. this.force = this.force.toLowerCase();
  27. if(this.supports("multiple")){
  28. this.uploadType = this.force === 'form' ? 'form' : 'html5';
  29. }else{
  30. this.uploadType = 'iframe';
  31. }
  32. this.inherited(arguments);
  33. },
  34. upload: function(formData){
  35. formData = formData || {};
  36. formData.uploadType = this.uploadType;
  37. this.inherited(arguments);
  38. },
  39. submit: function(form){
  40. form = !!form ? form.tagName ? form : this.getForm() : this.getForm();
  41. var data = domForm.toObject(form);
  42. data.uploadType = this.uploadType;
  43. this.upload(data);
  44. },
  45. pdResize: function(size) {
  46. domAttr.set(this.displayInput, "size", size);
  47. },
  48. buildRendering: function(){
  49. this.inherited(arguments);
  50. this.pdResize(INPUT_BOX_SIZE);
  51. },
  52. _setDisabledAttr: function(disabled){
  53. this.inherited(arguments);
  54. this.inputNode.disabled = disabled;
  55. this.displayInput.disabled = disabled;
  56. },
  57. onComplete: function(response, isGovernorCheck) {
  58. //overwrite dojo default event handler to block the reset for governor check request.
  59. if (!isGovernorCheck){
  60. this.reset();
  61. }
  62. }
  63. });
  64. return Uploader;
  65. });