/source/Plug-in/swfupload/FileUploadField.js

http://prosporous.googlecode.com/ · JavaScript · 137 lines · 64 code · 21 blank · 52 comment · 3 complexity · e34cd7c6359ef7c15635dbae2aa707d0 MD5 · raw file

  1. /*
  2. * Ext JS Library 2.2
  3. * Copyright(c) 2006-2008, Ext JS, LLC.
  4. * licensing@extjs.com
  5. *
  6. * http://extjs.com/license
  7. */
  8. Ext.form.FileUploadField = Ext.extend(Ext.form.TextField, {
  9. /**
  10. * @cfg {String} buttonText The button text to display on the upload button (defaults to
  11. * 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
  12. * value will be used instead if available.
  13. */
  14. buttonText: 'Browse...',
  15. /**
  16. * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
  17. * text field (defaults to false). If true, all inherited TextField members will still be available.
  18. */
  19. buttonOnly: false,
  20. /**
  21. * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
  22. * (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
  23. */
  24. buttonOffset: 3,
  25. /**
  26. * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
  27. */
  28. // private
  29. readOnly: true,
  30. /**
  31. * @hide
  32. * @method autoSize
  33. */
  34. autoSize: Ext.emptyFn,
  35. // private
  36. initComponent: function(){
  37. Ext.form.FileUploadField.superclass.initComponent.call(this);
  38. this.addEvents(
  39. /**
  40. * @event fileselected
  41. * Fires when the underlying file input field's value has changed from the user
  42. * selecting a new file from the system file selection dialog.
  43. * @param {Ext.form.FileUploadField} this
  44. * @param {String} value The file value returned by the underlying file input field
  45. */
  46. 'fileselected'
  47. );
  48. },
  49. // private
  50. onRender : function(ct, position){
  51. Ext.form.FileUploadField.superclass.onRender.call(this, ct, position);
  52. this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
  53. this.el.addClass('x-form-file-text');
  54. //this.el.dom.removeAttribute('name');
  55. // this.fileInput = this.wrap.createChild({
  56. // id: this.getFileInputId(),
  57. // name: this.name||this.getId(),
  58. // cls: 'x-form-file',
  59. // tag: 'input',
  60. // type: 'button',
  61. // size: 1
  62. // });
  63. var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
  64. text: this.buttonText
  65. });
  66. this.button = new Ext.Button(Ext.apply(btnCfg, {
  67. renderTo: this.wrap,
  68. cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
  69. }));
  70. if(this.buttonOnly){
  71. this.el.hide();
  72. this.wrap.setWidth(this.button.getEl().getWidth());
  73. }
  74. this.button.on('click', function(a,b,c){
  75. var dialog = new UploadDialog({
  76. uploadUrl : '/sa/upload/file.php',
  77. filePostName : 'Filedata',
  78. flashUrl : '/Plug-in/upload/swfupload.swf',
  79. fileSize : '100 MB',
  80. fileTypes : '*.jpg;*.gif;*.bmp;*.png;*.rar;*.zip;*.doc;*.xls;*.ppt;*.txt;*.rmvb;*.rn;*.wmv;*.flv;*.swf',
  81. fileTypesDescription : '????',
  82. opener:this.id,
  83. scope : this
  84. })
  85. dialog.show();
  86. }, this);
  87. },
  88. // private
  89. getFileInputId: function(){
  90. return this.id+'-file';
  91. },
  92. // private
  93. onResize : function(w, h){
  94. Ext.form.FileUploadField.superclass.onResize.call(this, w, h);
  95. this.wrap.setWidth(w);
  96. if(!this.buttonOnly){
  97. var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
  98. this.el.setWidth(w);
  99. }
  100. },
  101. // private
  102. preFocus : Ext.emptyFn,
  103. // private
  104. getResizeEl : function(){
  105. return this.wrap;
  106. },
  107. // private
  108. getPositionEl : function(){
  109. return this.wrap;
  110. },
  111. // private
  112. alignErrorIcon : function(){
  113. this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
  114. }
  115. });
  116. Ext.reg('fileuploadfield', Ext.form.FileUploadField);