Textarea.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 text = value.replace(reg,"<br/>");
  29. this.node.set("html", text);
  30. }
  31. },
  32. _loadNodeEdit: function(){
  33. var input = new Element("textarea", {"styles": {
  34. "background": "transparent",
  35. "width": "100%",
  36. "border": "0px"
  37. }});
  38. input.set(this.json.properties);
  39. if( this.form.json.textareaDisableResize )input.setStyle("resize","none");
  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. //this.node = input;
  49. this.node.set({
  50. "id": this.json.id,
  51. "MWFType": this.json.type
  52. });
  53. this.node.addEvent("change", function(){
  54. this._setBusinessData(this.getInputData());
  55. }.bind(this));
  56. this.node.getFirst().addEvent("blur", function(){
  57. this.validation();
  58. }.bind(this));
  59. this.node.getFirst().addEvent("keyup", function(){
  60. this.validationMode();
  61. }.bind(this));
  62. },
  63. _afterLoaded: function(){
  64. if (!this.readonly){
  65. this.loadDescription();
  66. }
  67. },
  68. loadDescription: function(){
  69. var v = this._getBusinessData();
  70. if (!v){
  71. if (this.json.description){
  72. var size = this.node.getFirst().getSize();
  73. var w = size.x-23;
  74. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  75. this.descriptionNode.setStyles({
  76. "width": ""+w+"px",
  77. "height": ""+size.y+"px",
  78. "line-height": ""+size.y+"px"
  79. });
  80. this.setDescriptionEvent();
  81. }
  82. }
  83. },
  84. setDescriptionEvent: function(){
  85. if (this.descriptionNode){
  86. if (COMMON.Browser.Platform.name==="ios"){
  87. this.descriptionNode.addEvents({
  88. "click": function(){
  89. this.descriptionNode.setStyle("display", "none");
  90. this.node.getFirst().focus();
  91. }.bind(this)
  92. });
  93. }else if (COMMON.Browser.Platform.name==="android"){
  94. this.descriptionNode.addEvents({
  95. "click": function(){
  96. this.descriptionNode.setStyle("display", "none");
  97. this.node.getFirst().focus();
  98. }.bind(this)
  99. });
  100. }else{
  101. this.descriptionNode.addEvents({
  102. "click": function(){
  103. this.descriptionNode.setStyle("display", "none");
  104. this.node.getFirst().focus();
  105. }.bind(this)
  106. });
  107. }
  108. this.node.getFirst().addEvents({
  109. "focus": function(){
  110. this.descriptionNode.setStyle("display", "none");
  111. }.bind(this),
  112. "blur": function(){
  113. if (!this.node.getFirst().get("value")) this.descriptionNode.setStyle("display", "block");
  114. }.bind(this)
  115. });
  116. }
  117. }
  118. });