Textarea.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. this._setBusinessData(value);
  25. if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
  26. if (this.readonly || this.json.isReadonly){
  27. var reg = new RegExp("\n","g");
  28. var reg2 = new RegExp("\u003c","g"); //尖括号转义,否则内容会截断
  29. var reg3 = new RegExp("\u003e","g");
  30. var text = value.replace(reg2,"&lt").replace(reg3,"&gt").replace(reg,"<br/>");
  31. this.node.set("html", text);
  32. }
  33. },
  34. _resetNodeEdit: function(){
  35. var input = new Element("textarea", {"styles": {
  36. "background": "transparent",
  37. "width": "100%",
  38. "border": "0px"
  39. }});
  40. var node = new Element("div", {"styles": {
  41. "ovwrflow": "hidden",
  42. "position": "relative",
  43. "padding-right": "2px"
  44. }}).inject(this.node, "after");
  45. input.inject(node);
  46. this.node.destroy();
  47. this.node = node;
  48. },
  49. _loadNodeEdit: function(){
  50. if (!this.json.preprocessing) this._resetNodeEdit();
  51. var input = this.node.getFirst();
  52. input.set(this.json.properties);
  53. if( this.form.json.textareaDisableResize )input.setStyle("resize","none");
  54. this.node.set({
  55. "id": this.json.id,
  56. "MWFType": this.json.type
  57. });
  58. this.node.addEvent("change", function(){
  59. this._setBusinessData(this.getInputData());
  60. }.bind(this));
  61. this.node.getFirst().addEvent("blur", function(){
  62. this.validation();
  63. }.bind(this));
  64. this.node.getFirst().addEvent("keyup", function(){
  65. this.validationMode();
  66. }.bind(this));
  67. },
  68. _afterLoaded: function(){
  69. if (!this.readonly){
  70. this.loadDescription();
  71. }
  72. },
  73. loadDescription: function(){
  74. if (this.readonly || this.json.isReadonly)return;
  75. var v = this._getBusinessData();
  76. if (!v){
  77. if (this.json.description){
  78. var size = this.node.getFirst().getSize();
  79. var w = size.x-3;
  80. if( this.json.showIcon!='no' && !this.form.json.hideModuleIcon ){
  81. w = size.x-23;
  82. }
  83. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  84. this.descriptionNode.setStyles({
  85. "width": ""+w+"px",
  86. "height": ""+size.y+"px",
  87. "line-height": ""+size.y+"px"
  88. });
  89. this.setDescriptionEvent();
  90. }
  91. }
  92. },
  93. setDescriptionEvent: function(){
  94. if (this.descriptionNode){
  95. if (COMMON.Browser.Platform.name==="ios"){
  96. this.descriptionNode.addEvents({
  97. "click": function(){
  98. this.descriptionNode.setStyle("display", "none");
  99. this.node.getFirst().focus();
  100. }.bind(this)
  101. });
  102. }else if (COMMON.Browser.Platform.name==="android"){
  103. this.descriptionNode.addEvents({
  104. "click": function(){
  105. this.descriptionNode.setStyle("display", "none");
  106. this.node.getFirst().focus();
  107. }.bind(this)
  108. });
  109. }else{
  110. this.descriptionNode.addEvents({
  111. "click": function(){
  112. this.descriptionNode.setStyle("display", "none");
  113. this.node.getFirst().focus();
  114. }.bind(this)
  115. });
  116. }
  117. this.node.getFirst().addEvents({
  118. "focus": function(){
  119. this.descriptionNode.setStyle("display", "none");
  120. }.bind(this),
  121. "blur": function(){
  122. if (!this.node.getFirst().get("value")) this.descriptionNode.setStyle("display", "block");
  123. }.bind(this)
  124. });
  125. }
  126. }
  127. });