Number.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. MWF.xDesktop.requireApp("process.Xform", "Textfield", null, false);
  2. MWF.xApplication.process.Xform.Number = MWF.APPNumber = new Class({
  3. Implements: [Events],
  4. Extends: MWF.APPTextfield,
  5. iconStyle: "numberIcon",
  6. getInputData: function(){
  7. var n = this.node.getElement("input").get("value").toFloat();
  8. if ((isNaN(n))) {this.setData('0')};
  9. return (isNaN(n)) ? 0 : n;
  10. },
  11. validationFormat: function(){
  12. debugger;
  13. var n = this.node.getElement("input").get("value");
  14. if (isNaN(n)) {
  15. this.notValidationMode(MWF.xApplication.process.Xform.LP.notValidation_number);
  16. return false;
  17. }
  18. var v = n.toFloat();
  19. if (v){
  20. if (this.json.decimals && (this.json.decimals!="*")){
  21. var p = Math.pow(10,this.json.decimals);
  22. var f_x = Math.round(v*p)/p;
  23. var s_x = f_x.toString();
  24. var pos_decimal = s_x.indexOf('.');
  25. if (pos_decimal < 0){
  26. pos_decimal = s_x.length;
  27. s_x += '.';
  28. }
  29. while (s_x.length <= pos_decimal + 2){
  30. s_x += '0';
  31. }
  32. this.node.getFirst().set("value", s_x);
  33. }
  34. }
  35. return true;
  36. },
  37. validationConfigItem: function(routeName, data){
  38. var flag = (data.status=="all") ? true: (routeName == data.decision);
  39. if (flag){
  40. var n = this.getInputData();
  41. var v = (data.valueType=="value") ? n : n.length;
  42. switch (data.operateor){
  43. case "isnull":
  44. if (!v && v.toString()!=='0'){
  45. this.notValidationMode(data.prompt);
  46. return false;
  47. }
  48. break;
  49. case "notnull":
  50. if (v){
  51. this.notValidationMode(data.prompt);
  52. return false;
  53. }
  54. break;
  55. case "gt":
  56. if (v>data.value){
  57. this.notValidationMode(data.prompt);
  58. return false;
  59. }
  60. break;
  61. case "lt":
  62. if (v<data.value){
  63. this.notValidationMode(data.prompt);
  64. return false;
  65. }
  66. break;
  67. case "equal":
  68. if (v==data.value){
  69. this.notValidationMode(data.prompt);
  70. return false;
  71. }
  72. break;
  73. case "neq":
  74. if (v!=data.value){
  75. this.notValidationMode(data.prompt);
  76. return false;
  77. }
  78. break;
  79. case "contain":
  80. if (v.indexOf(data.value)!=-1){
  81. this.notValidationMode(data.prompt);
  82. return false;
  83. }
  84. break;
  85. case "notcontain":
  86. if (v.indexOf(data.value)==-1){
  87. this.notValidationMode(data.prompt);
  88. return false;
  89. }
  90. break;
  91. }
  92. }
  93. return true;
  94. },
  95. validationConfig: function(routeName, opinion){
  96. if (this.json.validationConfig){
  97. if (this.json.validationConfig.length){
  98. for (var i=0; i<this.json.validationConfig.length; i++) {
  99. var data = this.json.validationConfig[i];
  100. if (!this.validationConfigItem(routeName, data)) return false;
  101. }
  102. }
  103. return true;
  104. }
  105. return true;
  106. },
  107. validation: function(routeName, opinion){
  108. if (!this.validationFormat()) return false;
  109. if (!this.validationConfig(routeName, opinion)) return false;
  110. if (!this.json.validation) return true;
  111. if (!this.json.validation.code) return true;
  112. var flag = this.form.Macro.exec(this.json.validation.code, this);
  113. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  114. if (flag.toString()!="true"){
  115. this.notValidationMode(flag);
  116. return false;
  117. }
  118. return true;
  119. },
  120. _loadNodeEdit: function(){
  121. var input = new Element("input", {
  122. "styles": {
  123. "background": "transparent",
  124. "width": "100%",
  125. "border": "0px"
  126. }
  127. });
  128. input.set(this.json.properties);
  129. var node = new Element("div", {"styles": {
  130. "overflow": "hidden",
  131. "position": "relative",
  132. "margin-right": "20px",
  133. "padding-right": "4px"
  134. }}).inject(this.node, "after");
  135. input.inject(node);
  136. this.node.destroy();
  137. this.node = node;
  138. this.node.set({
  139. "id": this.json.id,
  140. "MWFType": this.json.type,
  141. "events": {
  142. "click": this.clickSelect.bind(this)
  143. }
  144. });
  145. if (this.json.showIcon!='no' && !this.form.json.hideModuleIcon) {
  146. this.iconNode = new Element("div", {
  147. "styles": this.form.css[this.iconStyle]
  148. }).inject(this.node, "before");
  149. }else if( this.form.json.nodeStyleWithhideModuleIcon ){
  150. this.node.setStyles(this.form.json.nodeStyleWithhideModuleIcon)
  151. }
  152. this.node.getFirst().addEvent("change", function(){
  153. this.validationMode();
  154. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  155. }.bind(this));
  156. this.node.getFirst().addEvent("blur", function(){
  157. this.validation();
  158. }.bind(this));
  159. this.node.getFirst().addEvent("keyup", function(){
  160. this.validationMode();
  161. }.bind(this));
  162. },
  163. getValue: function(){
  164. var value = this._getBusinessData();
  165. if (!value) value = this._computeValue();
  166. return value || "0";
  167. }
  168. });