Textarea.js 7.5 KB

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