Textarea.js 6.4 KB

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