PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/webapp/lib/extjs/docs/source/File.html

https://bitbucket.org/glebiuskv/extjs-overlay
HTML | 276 lines | 244 code | 32 blank | 0 comment | 0 complexity | 1f4e0270fd27a74a08b29c3c1dee8bd8 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-form-field-File'>/**
  19. </span> * @docauthor Jason Johnston &lt;jason@sencha.com&gt;
  20. *
  21. * A file upload field which has custom styling and allows control over the button text and other
  22. * features of {@link Ext.form.field.Text text fields} like {@link Ext.form.field.Text#emptyText empty text}.
  23. * It uses a hidden file input element behind the scenes to allow user selection of a file and to
  24. * perform the actual upload during {@link Ext.form.Basic#submit form submit}.
  25. *
  26. * Because there is no secure cross-browser way to programmatically set the value of a file input,
  27. * the standard Field `setValue` method is not implemented. The `{@link #getValue}` method will return
  28. * a value that is browser-dependent; some have just the file name, some have a full path, some use
  29. * a fake path.
  30. *
  31. * **IMPORTANT:** File uploads are not performed using normal 'Ajax' techniques; see the description for
  32. * {@link Ext.form.Basic#hasUpload} for details.
  33. *
  34. * # Example Usage
  35. *
  36. * @example
  37. * Ext.create('Ext.form.Panel', {
  38. * title: 'Upload a Photo',
  39. * width: 400,
  40. * bodyPadding: 10,
  41. * frame: true,
  42. * renderTo: Ext.getBody(),
  43. * items: [{
  44. * xtype: 'filefield',
  45. * name: 'photo',
  46. * fieldLabel: 'Photo',
  47. * labelWidth: 50,
  48. * msgTarget: 'side',
  49. * allowBlank: false,
  50. * anchor: '100%',
  51. * buttonText: 'Select Photo...'
  52. * }],
  53. *
  54. * buttons: [{
  55. * text: 'Upload',
  56. * handler: function() {
  57. * var form = this.up('form').getForm();
  58. * if(form.isValid()){
  59. * form.submit({
  60. * url: 'photo-upload.php',
  61. * waitMsg: 'Uploading your photo...',
  62. * success: function(fp, o) {
  63. * Ext.Msg.alert('Success', 'Your photo &quot;' + o.result.file + '&quot; has been uploaded.');
  64. * }
  65. * });
  66. * }
  67. * }
  68. * }]
  69. * });
  70. */
  71. Ext.define('Ext.form.field.File', {
  72. extend: 'Ext.form.field.Trigger',
  73. alias: ['widget.filefield', 'widget.fileuploadfield'],
  74. alternateClassName: ['Ext.form.FileUploadField', 'Ext.ux.form.FileUploadField', 'Ext.form.File'],
  75. requires: [
  76. 'Ext.form.field.FileButton'
  77. ],
  78. //&lt;locale&gt;
  79. <span id='Ext-form-field-File-cfg-buttonText'> /**
  80. </span> * @cfg {String} buttonText
  81. * The button text to display on the upload button. Note that if you supply a value for
  82. * {@link #buttonConfig}, the buttonConfig.text value will be used instead if available.
  83. */
  84. buttonText: 'Browse...',
  85. //&lt;/locale&gt;
  86. <span id='Ext-form-field-File-cfg-buttonOnly'> /**
  87. </span> * @cfg {Boolean} buttonOnly
  88. * True to display the file upload field as a button with no visible text field. If true, all
  89. * inherited Text members will still be available.
  90. */
  91. buttonOnly: false,
  92. <span id='Ext-form-field-File-cfg-buttonMargin'> /**
  93. </span> * @cfg {Number} buttonMargin
  94. * The number of pixels of space reserved between the button and the text field. Note that this only
  95. * applies if {@link #buttonOnly} = false.
  96. */
  97. buttonMargin: 3,
  98. <span id='Ext-form-field-File-cfg-clearOnSubmit'> /**
  99. </span> * @cfg {Boolean} clearOnSubmit
  100. * True to clear the selected file value when the form this field belongs to
  101. * is submitted to the server.
  102. */
  103. clearOnSubmit: true,
  104. <span id='Ext-form-field-File-cfg-buttonConfig'> /**
  105. </span> * @cfg {Object} buttonConfig
  106. * A standard {@link Ext.button.Button} config object.
  107. */
  108. <span id='Ext-form-field-File-event-change'> /**
  109. </span> * @event change
  110. * Fires when the underlying file input field's value has changed from the user selecting a new file from the system
  111. * file selection dialog.
  112. * @param {Ext.ux.form.FileUploadField} this
  113. * @param {String} value The file value returned by the underlying file input field
  114. */
  115. <span id='Ext-form-field-File-property-fileInputEl'> /**
  116. </span> * @property {Ext.Element} fileInputEl
  117. * A reference to the invisible file input element created for this upload field. Only populated after this
  118. * component is rendered.
  119. */
  120. <span id='Ext-form-field-File-property-button'> /**
  121. </span> * @property {Ext.button.Button} button
  122. * A reference to the trigger Button component created for this upload field. Only populated after this component is
  123. * rendered.
  124. */
  125. <span id='Ext-form-field-File-property-extraFieldBodyCls'> // private
  126. </span> extraFieldBodyCls: Ext.baseCSSPrefix + 'form-file-wrap',
  127. <span id='Ext-form-field-File-cfg-readOnly'> /**
  128. </span> * @cfg {Boolean} readOnly
  129. * Unlike with other form fields, the readOnly config defaults to true in File field.
  130. */
  131. readOnly: true,
  132. <span id='Ext-form-field-File-property-triggerNoEditCls'> /**
  133. </span> * Do not show hand pointer over text field since file choose dialog is only shown when clicking in the button
  134. * @private
  135. */
  136. triggerNoEditCls: '',
  137. <span id='Ext-form-field-File-cfg-componentLayout'> // private
  138. </span> componentLayout: 'triggerfield',
  139. <span id='Ext-form-field-File-property-childEls'> // private. Extract the file element, button outer element, and button active element.
  140. </span> childEls: ['browseButtonWrap'],
  141. <span id='Ext-form-field-File-method-onRender'> // private
  142. </span> onRender: function() {
  143. var me = this,
  144. id = me.id,
  145. inputEl;
  146. me.callParent(arguments);
  147. inputEl = me.inputEl;
  148. inputEl.dom.name = ''; //name goes on the fileInput, not the text input
  149. // render the button here. This isn't ideal, however it will be
  150. // rendered before layouts are resumed, also we modify the DOM
  151. // below anyway
  152. me.button = new Ext.form.field.FileButton(Ext.apply({
  153. renderTo: id + '-browseButtonWrap',
  154. ownerCt: me,
  155. ownerLayout: me.componentLayout,
  156. id: id + '-button',
  157. ui: me.ui,
  158. disabled: me.disabled,
  159. text: me.buttonText,
  160. style: me.buttonOnly ? '' : me.getButtonMarginProp() + me.buttonMargin + 'px',
  161. inputName: me.getName(),
  162. listeners: {
  163. scope: me,
  164. change: me.onFileChange
  165. }
  166. }, me.buttonConfig));
  167. me.fileInputEl = me.button.fileInputEl;
  168. if (me.buttonOnly) {
  169. me.inputCell.setDisplayed(false);
  170. }
  171. // Ensure the trigger cell is sized correctly upon render
  172. me.browseButtonWrap.dom.style.width = (me.browseButtonWrap.dom.lastChild.offsetWidth + me.button.getEl().getMargin('lr')) + 'px';
  173. if (Ext.isIE) {
  174. me.button.getEl().repaint();
  175. }
  176. },
  177. <span id='Ext-form-field-File-method-getTriggerMarkup'> /**
  178. </span> * Gets the markup to be inserted into the subTplMarkup.
  179. */
  180. getTriggerMarkup: function() {
  181. return '&lt;td id=&quot;' + this.id + '-browseButtonWrap&quot;&gt;&lt;/td&gt;';
  182. },
  183. <span id='Ext-form-field-File-method-onFileChange'> /**
  184. </span> * @private Event handler fired when the user selects a file.
  185. */
  186. onFileChange: function(button, e, value) {
  187. this.lastValue = null; // force change event to get fired even if the user selects a file with the same name
  188. Ext.form.field.File.superclass.setValue.call(this, value);
  189. },
  190. <span id='Ext-form-field-File-method-setValue'> /**
  191. </span> * Overridden to do nothing
  192. * @method
  193. */
  194. setValue: Ext.emptyFn,
  195. <span id='Ext-form-field-File-method-reset'> reset : function(){
  196. </span> var me = this,
  197. clear = me.clearOnSubmit;
  198. if (me.rendered) {
  199. me.button.reset(clear);
  200. me.fileInputEl = me.button.fileInputEl;
  201. if (clear) {
  202. me.inputEl.dom.value = '';
  203. }
  204. }
  205. me.callParent();
  206. },
  207. <span id='Ext-form-field-File-method-onShow'> onShow: function(){
  208. </span> this.callParent();
  209. // If we started out hidden, the button may have a messed up layout
  210. // since we don't act like a container
  211. this.button.updateLayout();
  212. },
  213. <span id='Ext-form-field-File-method-onDisable'> onDisable: function(){
  214. </span> this.callParent();
  215. this.button.disable();
  216. },
  217. <span id='Ext-form-field-File-method-onEnable'> onEnable: function(){
  218. </span> this.callParent();
  219. this.button.enable();
  220. },
  221. <span id='Ext-form-field-File-method-isFileUpload'> isFileUpload: function() {
  222. </span> return true;
  223. },
  224. <span id='Ext-form-field-File-method-extractFileInput'> extractFileInput: function() {
  225. </span> var fileInput = this.button.fileInputEl.dom;
  226. this.reset();
  227. return fileInput;
  228. },
  229. <span id='Ext-form-field-File-method-restoreInput'> restoreInput: function(el) {
  230. </span> var button = this.button;
  231. button.restoreInput(el);
  232. this.fileInputEl = button.fileInputEl;
  233. },
  234. <span id='Ext-form-field-File-method-onDestroy'> onDestroy: function(){
  235. </span> Ext.destroyMembers(this, 'button');
  236. delete this.fileInputEl;
  237. this.callParent();
  238. },
  239. <span id='Ext-form-field-File-method-getButtonMarginProp'> getButtonMarginProp: function() {
  240. </span> return 'margin-left:';
  241. }
  242. });</pre>
  243. </body>
  244. </html>