Textarea.js 7.2 KB

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