Web Interface For Lite Argus Control modules
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.

192 lines
6.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. Ext.ns('Ext.ux.form');
  16. /**
  17. * @class Ext.ux.form.FileUploadField
  18. * @extends Ext.form.TextField
  19. * Creates a file upload field.
  20. * @xtype fileuploadfield
  21. */
  22. Ext.ux.form.FileUploadField = Ext.extend(Ext.form.TextField, {
  23. <div id="cfg-Ext.ux.form.FileUploadField-buttonText"></div>/**
  24. * @cfg {String} buttonText The button text to display on the upload button (defaults to
  25. * 'Browse...'). Note that if you supply a value for {@link #buttonCfg}, the buttonCfg.text
  26. * value will be used instead if available.
  27. */
  28. buttonText: 'Browse...',
  29. <div id="cfg-Ext.ux.form.FileUploadField-buttonOnly"></div>/**
  30. * @cfg {Boolean} buttonOnly True to display the file upload field as a button with no visible
  31. * text field (defaults to false). If true, all inherited TextField members will still be available.
  32. */
  33. buttonOnly: false,
  34. <div id="cfg-Ext.ux.form.FileUploadField-buttonOffset"></div>/**
  35. * @cfg {Number} buttonOffset The number of pixels of space reserved between the button and the text field
  36. * (defaults to 3). Note that this only applies if {@link #buttonOnly} = false.
  37. */
  38. buttonOffset: 3,
  39. <div id="cfg-Ext.ux.form.FileUploadField-buttonCfg"></div>/**
  40. * @cfg {Object} buttonCfg A standard {@link Ext.Button} config object.
  41. */
  42. // private
  43. readOnly: true,
  44. <div id="method-Ext.ux.form.FileUploadField-autoSize"></div>/**
  45. * @hide
  46. * @method autoSize
  47. */
  48. autoSize: Ext.emptyFn,
  49. // private
  50. initComponent: function(){
  51. Ext.ux.form.FileUploadField.superclass.initComponent.call(this);
  52. this.addEvents(
  53. <div id="event-Ext.ux.form.FileUploadField-fileselected"></div>/**
  54. * @event fileselected
  55. * Fires when the underlying file input field's value has changed from the user
  56. * selecting a new file from the system file selection dialog.
  57. * @param {Ext.ux.form.FileUploadField} this
  58. * @param {String} value The file value returned by the underlying file input field
  59. */
  60. 'fileselected'
  61. );
  62. },
  63. // private
  64. onRender : function(ct, position){
  65. Ext.ux.form.FileUploadField.superclass.onRender.call(this, ct, position);
  66. this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'});
  67. this.el.addClass('x-form-file-text');
  68. this.el.dom.removeAttribute('name');
  69. this.createFileInput();
  70. var btnCfg = Ext.applyIf(this.buttonCfg || {}, {
  71. text: this.buttonText
  72. });
  73. this.button = new Ext.Button(Ext.apply(btnCfg, {
  74. renderTo: this.wrap,
  75. cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '')
  76. }));
  77. if(this.buttonOnly){
  78. this.el.hide();
  79. this.wrap.setWidth(this.button.getEl().getWidth());
  80. }
  81. this.bindListeners();
  82. this.resizeEl = this.positionEl = this.wrap;
  83. },
  84. bindListeners: function(){
  85. this.fileInput.on({
  86. scope: this,
  87. mouseenter: function() {
  88. this.button.addClass(['x-btn-over','x-btn-focus'])
  89. },
  90. mouseleave: function(){
  91. this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
  92. },
  93. mousedown: function(){
  94. this.button.addClass('x-btn-click')
  95. },
  96. mouseup: function(){
  97. this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
  98. },
  99. change: function(){
  100. var v = this.fileInput.dom.value;
  101. this.setValue(v);
  102. this.fireEvent('fileselected', this, v);
  103. }
  104. });
  105. },
  106. createFileInput : function() {
  107. this.fileInput = this.wrap.createChild({
  108. id: this.getFileInputId(),
  109. name: this.name||this.getId(),
  110. cls: 'x-form-file',
  111. tag: 'input',
  112. type: 'file',
  113. size: 1
  114. });
  115. },
  116. reset : function(){
  117. this.fileInput.remove();
  118. this.createFileInput();
  119. this.bindListeners();
  120. Ext.ux.form.FileUploadField.superclass.reset.call(this);
  121. },
  122. // private
  123. getFileInputId: function(){
  124. return this.id + '-file';
  125. },
  126. // private
  127. onResize : function(w, h){
  128. Ext.ux.form.FileUploadField.superclass.onResize.call(this, w, h);
  129. this.wrap.setWidth(w);
  130. if(!this.buttonOnly){
  131. var w = this.wrap.getWidth() - this.button.getEl().getWidth() - this.buttonOffset;
  132. this.el.setWidth(w);
  133. }
  134. },
  135. // private
  136. onDestroy: function(){
  137. Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);
  138. Ext.destroy(this.fileInput, this.button, this.wrap);
  139. },
  140. onDisable: function(){
  141. Ext.ux.form.FileUploadField.superclass.onDisable.call(this);
  142. this.doDisable(true);
  143. },
  144. onEnable: function(){
  145. Ext.ux.form.FileUploadField.superclass.onEnable.call(this);
  146. this.doDisable(false);
  147. },
  148. // private
  149. doDisable: function(disabled){
  150. this.fileInput.dom.disabled = disabled;
  151. this.button.setDisabled(disabled);
  152. },
  153. // private
  154. preFocus : Ext.emptyFn,
  155. // private
  156. alignErrorIcon : function(){
  157. this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
  158. }
  159. });
  160. Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField);
  161. // backwards compat
  162. Ext.form.FileUploadField = Ext.ux.form.FileUploadField;
  163. </pre>
  164. </body>
  165. </html>