Textarea.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. MWF.xDesktop.requireApp("process.Xform", "$Input", null, false);
  2. MWF.xApplication.process.Xform.Textarea = MWF.APPTextarea = new Class({
  3. Implements: [Events],
  4. Extends: MWF.APP$Input,
  5. _loadUserInterface: function(){
  6. this._loadNode();
  7. if (this.json.compute == "show"){
  8. this._setValue(this._computeValue());
  9. }else{
  10. this._loadValue();
  11. }
  12. },
  13. _loadNode: function(){
  14. if (this.readonly || this.json.isReadonly){
  15. this._loadNodeRead();
  16. }else{
  17. this._loadNodeEdit();
  18. }
  19. },
  20. _loadNodeRead: function(){
  21. this.node.empty();
  22. },
  23. _setValue: function(value){
  24. this.moduleValueAG = o2.AG.all(value).then(function(v){
  25. this.moduleValueAG = null;
  26. this._setBusinessData(v);
  27. if (this.node.getFirst()) this.node.getFirst().set("value", v || "");
  28. if (this.readonly || this.json.isReadonly){
  29. var reg = new RegExp("\n","g");
  30. var reg2 = new RegExp("\u003c","g"); //尖括号转义,否则内容会截断
  31. var reg3 = new RegExp("\u003e","g");
  32. var text = value.replace(reg2,"&lt").replace(reg3,"&gt").replace(reg,"<br/>");
  33. this.node.set("html", text);
  34. }
  35. }.bind(this));
  36. return value;
  37. // if (value && value.isAG){
  38. // this.moduleValueAG = value;
  39. // value.addResolve(function(v){
  40. // this._setValue(v);
  41. // }.bind(this));
  42. // }else{
  43. // this._setBusinessData(value);
  44. // if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
  45. // if (this.readonly || this.json.isReadonly){
  46. // var reg = new RegExp("\n","g");
  47. // var reg2 = new RegExp("\u003c","g"); //尖括号转义,否则内容会截断
  48. // var reg3 = new RegExp("\u003e","g");
  49. // var text = value.replace(reg2,"&lt").replace(reg3,"&gt").replace(reg,"<br/>");
  50. // this.node.set("html", text);
  51. // }
  52. // return value;
  53. // }
  54. },
  55. // _setValue: function(value){
  56. // this._setBusinessData(value);
  57. // if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
  58. // if (this.readonly || this.json.isReadonly){
  59. // var reg = new RegExp("\n","g");
  60. // var reg2 = new RegExp("\u003c","g"); //尖括号转义,否则内容会截断
  61. // var reg3 = new RegExp("\u003e","g");
  62. // var text = value.replace(reg2,"&lt").replace(reg3,"&gt").replace(reg,"<br/>");
  63. // this.node.set("html", text);
  64. // }
  65. // },
  66. _resetNodeEdit: function(){
  67. var input = new Element("textarea", {"styles": {
  68. "background": "transparent",
  69. "width": "100%",
  70. "border": "0px"
  71. }});
  72. var node = new Element("div", {"styles": {
  73. "ovwrflow": "hidden",
  74. "position": "relative",
  75. "padding-right": "2px"
  76. }}).inject(this.node, "after");
  77. input.inject(node);
  78. this.node.destroy();
  79. this.node = node;
  80. },
  81. _loadNodeEdit: function(){
  82. if (!this.json.preprocessing) this._resetNodeEdit();
  83. var input = this.node.getFirst();
  84. input.set(this.json.properties);
  85. if( this.form.json.textareaDisableResize )input.setStyle("resize","none");
  86. this.node.set({
  87. "id": this.json.id,
  88. "MWFType": this.json.type
  89. });
  90. this.node.addEvent("change", function(){
  91. this._setBusinessData(this.getInputData());
  92. }.bind(this));
  93. this.node.getFirst().addEvent("blur", function(){
  94. this.validation();
  95. }.bind(this));
  96. this.node.getFirst().addEvent("keyup", function(){
  97. this.validationMode();
  98. }.bind(this));
  99. },
  100. _afterLoaded: function(){
  101. if (!this.readonly){
  102. this.loadDescription();
  103. }
  104. },
  105. loadDescription: function(){
  106. if (this.readonly || this.json.isReadonly)return;
  107. var v = this._getBusinessData();
  108. if (!v){
  109. if (this.json.description){
  110. var size = this.node.getFirst().getSize();
  111. var w = size.x-3;
  112. if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ){
  113. w = size.x-23;
  114. }
  115. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  116. this.descriptionNode.setStyles({
  117. "width": ""+w+"px",
  118. "height": ""+size.y+"px",
  119. "line-height": ""+size.y+"px"
  120. });
  121. this.setDescriptionEvent();
  122. }
  123. }
  124. },
  125. setDescriptionEvent: function(){
  126. if (this.descriptionNode){
  127. if (COMMON.Browser.Platform.name==="ios"){
  128. this.descriptionNode.addEvents({
  129. "click": function(){
  130. this.descriptionNode.setStyle("display", "none");
  131. this.node.getFirst().focus();
  132. }.bind(this)
  133. });
  134. }else if (COMMON.Browser.Platform.name==="android"){
  135. this.descriptionNode.addEvents({
  136. "click": function(){
  137. this.descriptionNode.setStyle("display", "none");
  138. this.node.getFirst().focus();
  139. }.bind(this)
  140. });
  141. }else{
  142. this.descriptionNode.addEvents({
  143. "click": function(){
  144. this.descriptionNode.setStyle("display", "none");
  145. this.node.getFirst().focus();
  146. }.bind(this)
  147. });
  148. }
  149. this.node.getFirst().addEvents({
  150. "focus": function(){
  151. this.descriptionNode.setStyle("display", "none");
  152. }.bind(this),
  153. "blur": function(){
  154. if (!this.node.getFirst().get("value")) this.descriptionNode.setStyle("display", "block");
  155. }.bind(this)
  156. });
  157. }
  158. }
  159. });