Web UI for ARGUS server
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.

204 lines
7.5 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. <div id="cls-Ext.form.NumberField"></div>/**
  16. * @class Ext.form.NumberField
  17. * @extends Ext.form.TextField
  18. * Numeric text field that provides automatic keystroke filtering and numeric validation.
  19. * @constructor
  20. * Creates a new NumberField
  21. * @param {Object} config Configuration options
  22. * @xtype numberfield
  23. */
  24. Ext.form.NumberField = Ext.extend(Ext.form.TextField, {
  25. <div id="cfg-Ext.form.NumberField-stripCharsRe"></div>/**
  26. * @cfg {RegExp} stripCharsRe @hide
  27. */
  28. <div id="cfg-Ext.form.NumberField-maskRe"></div>/**
  29. * @cfg {RegExp} maskRe @hide
  30. */
  31. <div id="cfg-Ext.form.NumberField-fieldClass"></div>/**
  32. * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
  33. */
  34. fieldClass: "x-form-field x-form-num-field",
  35. <div id="cfg-Ext.form.NumberField-allowDecimals"></div>/**
  36. * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
  37. */
  38. allowDecimals : true,
  39. <div id="cfg-Ext.form.NumberField-decimalSeparator"></div>/**
  40. * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
  41. */
  42. decimalSeparator : ".",
  43. <div id="cfg-Ext.form.NumberField-decimalPrecision"></div>/**
  44. * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
  45. */
  46. decimalPrecision : 2,
  47. <div id="cfg-Ext.form.NumberField-allowNegative"></div>/**
  48. * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
  49. */
  50. allowNegative : true,
  51. <div id="cfg-Ext.form.NumberField-minValue"></div>/**
  52. * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
  53. */
  54. minValue : Number.NEGATIVE_INFINITY,
  55. <div id="cfg-Ext.form.NumberField-maxValue"></div>/**
  56. * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
  57. */
  58. maxValue : Number.MAX_VALUE,
  59. <div id="cfg-Ext.form.NumberField-minText"></div>/**
  60. * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
  61. */
  62. minText : "The minimum value for this field is {0}",
  63. <div id="cfg-Ext.form.NumberField-maxText"></div>/**
  64. * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
  65. */
  66. maxText : "The maximum value for this field is {0}",
  67. <div id="cfg-Ext.form.NumberField-nanText"></div>/**
  68. * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
  69. * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
  70. */
  71. nanText : "{0} is not a valid number",
  72. <div id="cfg-Ext.form.NumberField-baseChars"></div>/**
  73. * @cfg {String} baseChars The base set of characters to evaluate as valid numbers (defaults to '0123456789').
  74. */
  75. baseChars : "0123456789",
  76. <div id="cfg-Ext.form.NumberField-autoStripChars"></div>/**
  77. * @cfg {Boolean} autoStripChars True to automatically strip not allowed characters from the field. Defaults to <tt>false</tt>
  78. */
  79. autoStripChars: false,
  80. // private
  81. initEvents : function() {
  82. var allowed = this.baseChars + '';
  83. if (this.allowDecimals) {
  84. allowed += this.decimalSeparator;
  85. }
  86. if (this.allowNegative) {
  87. allowed += '-';
  88. }
  89. allowed = Ext.escapeRe(allowed);
  90. this.maskRe = new RegExp('[' + allowed + ']');
  91. if (this.autoStripChars) {
  92. this.stripCharsRe = new RegExp('[^' + allowed + ']', 'gi');
  93. }
  94. Ext.form.NumberField.superclass.initEvents.call(this);
  95. },
  96. <div id="method-Ext.form.NumberField-getErrors"></div>/**
  97. * Runs all of NumberFields validations and returns an array of any errors. Note that this first
  98. * runs TextField's validations, so the returned array is an amalgamation of all field errors.
  99. * The additional validations run test that the value is a number, and that it is within the
  100. * configured min and max values.
  101. * @param {Mixed} value The value to get errors for (defaults to the current field value)
  102. * @return {Array} All validation errors for this field
  103. */
  104. getErrors: function(value) {
  105. var errors = Ext.form.NumberField.superclass.getErrors.apply(this, arguments);
  106. value = Ext.isDefined(value) ? value : this.processValue(this.getRawValue());
  107. if (value.length < 1) { // if it's blank and textfield didn't flag it then it's valid
  108. return errors;
  109. }
  110. value = String(value).replace(this.decimalSeparator, ".");
  111. if(isNaN(value)){
  112. errors.push(String.format(this.nanText, value));
  113. }
  114. var num = this.parseValue(value);
  115. if (num < this.minValue) {
  116. errors.push(String.format(this.minText, this.minValue));
  117. }
  118. if (num > this.maxValue) {
  119. errors.push(String.format(this.maxText, this.maxValue));
  120. }
  121. return errors;
  122. },
  123. getValue : function() {
  124. return this.fixPrecision(this.parseValue(Ext.form.NumberField.superclass.getValue.call(this)));
  125. },
  126. setValue : function(v) {
  127. v = this.fixPrecision(v);
  128. v = Ext.isNumber(v) ? v : parseFloat(String(v).replace(this.decimalSeparator, "."));
  129. v = isNaN(v) ? '' : String(v).replace(".", this.decimalSeparator);
  130. return Ext.form.NumberField.superclass.setValue.call(this, v);
  131. },
  132. <div id="method-Ext.form.NumberField-setMinValue"></div>/**
  133. * Replaces any existing {@link #minValue} with the new value.
  134. * @param {Number} value The minimum value
  135. */
  136. setMinValue : function(value) {
  137. this.minValue = Ext.num(value, Number.NEGATIVE_INFINITY);
  138. },
  139. <div id="method-Ext.form.NumberField-setMaxValue"></div>/**
  140. * Replaces any existing {@link #maxValue} with the new value.
  141. * @param {Number} value The maximum value
  142. */
  143. setMaxValue : function(value) {
  144. this.maxValue = Ext.num(value, Number.MAX_VALUE);
  145. },
  146. // private
  147. parseValue : function(value) {
  148. value = parseFloat(String(value).replace(this.decimalSeparator, "."));
  149. return isNaN(value) ? '' : value;
  150. },
  151. /**
  152. * @private
  153. *
  154. */
  155. fixPrecision : function(value) {
  156. var nan = isNaN(value);
  157. if (!this.allowDecimals || this.decimalPrecision == -1 || nan || !value) {
  158. return nan ? '' : value;
  159. }
  160. return parseFloat(parseFloat(value).toFixed(this.decimalPrecision));
  161. },
  162. beforeBlur : function() {
  163. var v = this.parseValue(this.getRawValue());
  164. if (!Ext.isEmpty(v)) {
  165. this.setValue(v);
  166. }
  167. }
  168. });
  169. Ext.reg('numberfield', Ext.form.NumberField);
  170. </pre>
  171. </body>
  172. </html>