Textarea.js 7.3 KB

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