DataField-min.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.data.Field = function(D) {
  7. if (typeof D == "string") {
  8. D = {
  9. name : D
  10. }
  11. }
  12. Ext.apply(this, D);
  13. if (!this.type) {
  14. this.type = "auto"
  15. }
  16. var C = Ext.data.SortTypes;
  17. if (typeof this.sortType == "string") {
  18. this.sortType = C[this.sortType]
  19. }
  20. if (!this.sortType) {
  21. switch (this.type) {
  22. case "string" :
  23. this.sortType = C.asUCString;
  24. break;
  25. case "date" :
  26. this.sortType = C.asDate;
  27. break;
  28. default :
  29. this.sortType = C.none
  30. }
  31. }
  32. var E = /[\$,%]/g;
  33. if (!this.convert) {
  34. var B, A = this.dateFormat;
  35. switch (this.type) {
  36. case "" :
  37. case "auto" :
  38. case undefined :
  39. B = function(F) {
  40. return F
  41. };
  42. break;
  43. case "string" :
  44. B = function(F) {
  45. return (F === undefined || F === null) ? "" : String(F)
  46. };
  47. break;
  48. case "int" :
  49. B = function(F) {
  50. return F !== undefined && F !== null && F !== ""
  51. ? parseInt(String(F).replace(E, ""), 10)
  52. : ""
  53. };
  54. break;
  55. case "float" :
  56. B = function(F) {
  57. return F !== undefined && F !== null && F !== ""
  58. ? parseFloat(String(F).replace(E, ""), 10)
  59. : ""
  60. };
  61. break;
  62. case "bool" :
  63. case "boolean" :
  64. B = function(F) {
  65. return F === true || F === "true" || F == 1
  66. };
  67. break;
  68. case "date" :
  69. B = function(G) {
  70. if (!G) {
  71. return ""
  72. }
  73. if (G instanceof Date) {
  74. return G
  75. }
  76. if (A) {
  77. if (A == "timestamp") {
  78. return new Date(G * 1000)
  79. }
  80. if (A == "time") {
  81. return new Date(parseInt(G, 10))
  82. }
  83. return Date.parseDate(G, A)
  84. }
  85. var F = Date.parse(G);
  86. return F ? new Date(F) : null
  87. };
  88. break
  89. }
  90. this.convert = B
  91. }
  92. };
  93. Ext.data.Field.prototype = {
  94. dateFormat : null,
  95. defaultValue : "",
  96. mapping : null,
  97. sortType : null,
  98. sortDir : "ASC"
  99. };