Textarea.js 7.4 KB

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