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.

377 lines
15 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. <div id="cls-Ext.util.Format"></div>/**
  16. * @class Ext.util.Format
  17. * Reusable data formatting functions
  18. * @singleton
  19. */
  20. Ext.util.Format = function() {
  21. var trimRe = /^\s+|\s+$/g,
  22. stripTagsRE = /<\/?[^>]+>/gi,
  23. stripScriptsRe = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,
  24. nl2brRe = /\r?\n/g;
  25. return {
  26. <div id="method-Ext.util.Format-ellipsis"></div>/**
  27. * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
  28. * @param {String} value The string to truncate
  29. * @param {Number} length The maximum length to allow before truncating
  30. * @param {Boolean} word True to try to find a common work break
  31. * @return {String} The converted text
  32. */
  33. ellipsis : function(value, len, word) {
  34. if (value && value.length > len) {
  35. if (word) {
  36. var vs = value.substr(0, len - 2),
  37. index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));
  38. if (index == -1 || index < (len - 15)) {
  39. return value.substr(0, len - 3) + "...";
  40. } else {
  41. return vs.substr(0, index) + "...";
  42. }
  43. } else {
  44. return value.substr(0, len - 3) + "...";
  45. }
  46. }
  47. return value;
  48. },
  49. <div id="method-Ext.util.Format-undef"></div>/**
  50. * Checks a reference and converts it to empty string if it is undefined
  51. * @param {Mixed} value Reference to check
  52. * @return {Mixed} Empty string if converted, otherwise the original value
  53. */
  54. undef : function(value) {
  55. return value !== undefined ? value : "";
  56. },
  57. <div id="method-Ext.util.Format-defaultValue"></div>/**
  58. * Checks a reference and converts it to the default value if it's empty
  59. * @param {Mixed} value Reference to check
  60. * @param {String} defaultValue The value to insert of it's undefined (defaults to "")
  61. * @return {String}
  62. */
  63. defaultValue : function(value, defaultValue) {
  64. return value !== undefined && value !== '' ? value : defaultValue;
  65. },
  66. <div id="method-Ext.util.Format-htmlEncode"></div>/**
  67. * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
  68. * @param {String} value The string to encode
  69. * @return {String} The encoded text
  70. */
  71. htmlEncode : function(value) {
  72. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
  73. },
  74. <div id="method-Ext.util.Format-htmlDecode"></div>/**
  75. * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
  76. * @param {String} value The string to decode
  77. * @return {String} The decoded text
  78. */
  79. htmlDecode : function(value) {
  80. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  81. },
  82. <div id="method-Ext.util.Format-trim"></div>/**
  83. * Trims any whitespace from either side of a string
  84. * @param {String} value The text to trim
  85. * @return {String} The trimmed text
  86. */
  87. trim : function(value) {
  88. return String(value).replace(trimRe, "");
  89. },
  90. <div id="method-Ext.util.Format-substr"></div>/**
  91. * Returns a substring from within an original string
  92. * @param {String} value The original text
  93. * @param {Number} start The start index of the substring
  94. * @param {Number} length The length of the substring
  95. * @return {String} The substring
  96. */
  97. substr : function(value, start, length) {
  98. return String(value).substr(start, length);
  99. },
  100. <div id="method-Ext.util.Format-lowercase"></div>/**
  101. * Converts a string to all lower case letters
  102. * @param {String} value The text to convert
  103. * @return {String} The converted text
  104. */
  105. lowercase : function(value) {
  106. return String(value).toLowerCase();
  107. },
  108. <div id="method-Ext.util.Format-uppercase"></div>/**
  109. * Converts a string to all upper case letters
  110. * @param {String} value The text to convert
  111. * @return {String} The converted text
  112. */
  113. uppercase : function(value) {
  114. return String(value).toUpperCase();
  115. },
  116. <div id="method-Ext.util.Format-capitalize"></div>/**
  117. * Converts the first character only of a string to upper case
  118. * @param {String} value The text to convert
  119. * @return {String} The converted text
  120. */
  121. capitalize : function(value) {
  122. return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
  123. },
  124. // private
  125. call : function(value, fn) {
  126. if (arguments.length > 2) {
  127. var args = Array.prototype.slice.call(arguments, 2);
  128. args.unshift(value);
  129. return eval(fn).apply(window, args);
  130. } else {
  131. return eval(fn).call(window, value);
  132. }
  133. },
  134. <div id="method-Ext.util.Format-usMoney"></div>/**
  135. * Format a number as US currency
  136. * @param {Number/String} value The numeric value to format
  137. * @return {String} The formatted currency string
  138. */
  139. usMoney : function(v) {
  140. v = (Math.round((v-0)*100))/100;
  141. v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
  142. v = String(v);
  143. var ps = v.split('.'),
  144. whole = ps[0],
  145. sub = ps[1] ? '.'+ ps[1] : '.00',
  146. r = /(\d+)(\d{3})/;
  147. while (r.test(whole)) {
  148. whole = whole.replace(r, '$1' + ',' + '$2');
  149. }
  150. v = whole + sub;
  151. if (v.charAt(0) == '-') {
  152. return '-$' + v.substr(1);
  153. }
  154. return "$" + v;
  155. },
  156. <div id="method-Ext.util.Format-date"></div>/**
  157. * Parse a value into a formatted date using the specified format pattern.
  158. * @param {String/Date} value The value to format (Strings must conform to the format expected by the javascript Date object's <a href="http://www.w3schools.com/jsref/jsref_parse.asp">parse()</a> method)
  159. * @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')
  160. * @return {String} The formatted date string
  161. */
  162. date : function(v, format) {
  163. if (!v) {
  164. return "";
  165. }
  166. if (!Ext.isDate(v)) {
  167. v = new Date(Date.parse(v));
  168. }
  169. return v.dateFormat(format || "m/d/Y");
  170. },
  171. <div id="method-Ext.util.Format-dateRenderer"></div>/**
  172. * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
  173. * @param {String} format Any valid date format string
  174. * @return {Function} The date formatting function
  175. */
  176. dateRenderer : function(format) {
  177. return function(v) {
  178. return Ext.util.Format.date(v, format);
  179. };
  180. },
  181. <div id="method-Ext.util.Format-stripTags"></div>/**
  182. * Strips all HTML tags
  183. * @param {Mixed} value The text from which to strip tags
  184. * @return {String} The stripped text
  185. */
  186. stripTags : function(v) {
  187. return !v ? v : String(v).replace(stripTagsRE, "");
  188. },
  189. <div id="method-Ext.util.Format-stripScripts"></div>/**
  190. * Strips all script tags
  191. * @param {Mixed} value The text from which to strip script tags
  192. * @return {String} The stripped text
  193. */
  194. stripScripts : function(v) {
  195. return !v ? v : String(v).replace(stripScriptsRe, "");
  196. },
  197. <div id="method-Ext.util.Format-fileSize"></div>/**
  198. * Simple format for a file size (xxx bytes, xxx KB, xxx MB)
  199. * @param {Number/String} size The numeric value to format
  200. * @return {String} The formatted file size
  201. */
  202. fileSize : function(size) {
  203. if (size < 1024) {
  204. return size + " bytes";
  205. } else if (size < 1048576) {
  206. return (Math.round(((size*10) / 1024))/10) + " KB";
  207. } else {
  208. return (Math.round(((size*10) / 1048576))/10) + " MB";
  209. }
  210. },
  211. <div id="method-Ext.util.Format-math"></div>/**
  212. * It does simple math for use in a template, for example:<pre><code>
  213. * var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');
  214. * </code></pre>
  215. * @return {Function} A function that operates on the passed value.
  216. */
  217. math : function(){
  218. var fns = {};
  219. return function(v, a){
  220. if (!fns[a]) {
  221. fns[a] = new Function('v', 'return v ' + a + ';');
  222. }
  223. return fns[a](v);
  224. };
  225. }(),
  226. <div id="method-Ext.util.Format-round"></div>/**
  227. * Rounds the passed number to the required decimal precision.
  228. * @param {Number/String} value The numeric value to round.
  229. * @param {Number} precision The number of decimal places to which to round the first parameter's value.
  230. * @return {Number} The rounded value.
  231. */
  232. round : function(value, precision) {
  233. var result = Number(value);
  234. if (typeof precision == 'number') {
  235. precision = Math.pow(10, precision);
  236. result = Math.round(value * precision) / precision;
  237. }
  238. return result;
  239. },
  240. <div id="method-Ext.util.Format-number"></div>/**
  241. * Formats the number according to the format string.
  242. * <div style="margin-left:40px">examples (123456.789):
  243. * <div style="margin-left:10px">
  244. * 0 - (123456) show only digits, no precision<br>
  245. * 0.00 - (123456.78) show only digits, 2 precision<br>
  246. * 0.0000 - (123456.7890) show only digits, 4 precision<br>
  247. * 0,000 - (123,456) show comma and digits, no precision<br>
  248. * 0,000.00 - (123,456.78) show comma and digits, 2 precision<br>
  249. * 0,0.00 - (123,456.78) shortcut method, show comma and digits, 2 precision<br>
  250. * To reverse the grouping (,) and decimal (.) for international numbers, add /i to the end.
  251. * For example: 0.000,00/i
  252. * </div></div>
  253. * @param {Number} v The number to format.
  254. * @param {String} format The way you would like to format this text.
  255. * @return {String} The formatted number.
  256. */
  257. number: function(v, format) {
  258. if (!format) {
  259. return v;
  260. }
  261. v = Ext.num(v, NaN);
  262. if (isNaN(v)) {
  263. return '';
  264. }
  265. var comma = ',',
  266. dec = '.',
  267. i18n = false,
  268. neg = v < 0;
  269. v = Math.abs(v);
  270. if (format.substr(format.length - 2) == '/i') {
  271. format = format.substr(0, format.length - 2);
  272. i18n = true;
  273. comma = '.';
  274. dec = ',';
  275. }
  276. var hasComma = format.indexOf(comma) != -1,
  277. psplit = (i18n ? format.replace(/[^\d\,]/g, '') : format.replace(/[^\d\.]/g, '')).split(dec);
  278. if (1 < psplit.length) {
  279. v = v.toFixed(psplit[1].length);
  280. } else if(2 < psplit.length) {
  281. throw ('NumberFormatException: invalid format, formats should have no more than 1 period: ' + format);
  282. } else {
  283. v = v.toFixed(0);
  284. }
  285. var fnum = v.toString();
  286. psplit = fnum.split('.');
  287. if (hasComma) {
  288. var cnum = psplit[0],
  289. parr = [],
  290. j = cnum.length,
  291. m = Math.floor(j / 3),
  292. n = cnum.length % 3 || 3,
  293. i;
  294. for (i = 0; i < j; i += n) {
  295. if (i != 0) {
  296. n = 3;
  297. }
  298. parr[parr.length] = cnum.substr(i, n);
  299. m -= 1;
  300. }
  301. fnum = parr.join(comma);
  302. if (psplit[1]) {
  303. fnum += dec + psplit[1];
  304. }
  305. } else {
  306. if (psplit[1]) {
  307. fnum = psplit[0] + dec + psplit[1];
  308. }
  309. }
  310. return (neg ? '-' : '') + format.replace(/[\d,?\.?]+/, fnum);
  311. },
  312. <div id="method-Ext.util.Format-numberRenderer"></div>/**
  313. * Returns a number rendering function that can be reused to apply a number format multiple times efficiently
  314. * @param {String} format Any valid number format string for {@link #number}
  315. * @return {Function} The number formatting function
  316. */
  317. numberRenderer : function(format) {
  318. return function(v) {
  319. return Ext.util.Format.number(v, format);
  320. };
  321. },
  322. <div id="method-Ext.util.Format-plural"></div>/**
  323. * Selectively do a plural form of a word based on a numeric value. For example, in a template,
  324. * {commentCount:plural("Comment")} would result in "1 Comment" if commentCount was 1 or would be "x Comments"
  325. * if the value is 0 or greater than 1.
  326. * @param {Number} value The value to compare against
  327. * @param {String} singular The singular form of the word
  328. * @param {String} plural (optional) The plural form of the word (defaults to the singular with an "s")
  329. */
  330. plural : function(v, s, p) {
  331. return v +' ' + (v == 1 ? s : (p ? p : s+'s'));
  332. },
  333. <div id="method-Ext.util.Format-nl2br"></div>/**
  334. * Converts newline characters to the HTML tag &lt;br/>
  335. * @param {String} The string value to format.
  336. * @return {String} The string with embedded &lt;br/> tags in place of newlines.
  337. */
  338. nl2br : function(v) {
  339. return Ext.isEmpty(v) ? '' : v.replace(nl2brRe, '<br/>');
  340. }
  341. };
  342. }();
  343. </pre>
  344. </body>
  345. </html>