Textarea.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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){
  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. var node = new Element("div", {"styles": {
  40. "ovwrflow": "hidden",
  41. "position": "relative",
  42. "padding-right": "2px"
  43. }}).inject(this.node, "after");
  44. input.inject(node);
  45. this.node.destroy();
  46. this.node = node;
  47. //this.node = input;
  48. this.node.set({
  49. "id": this.json.id,
  50. "MWFType": this.json.type
  51. });
  52. this.node.addEvent("change", function(){
  53. this._setBusinessData(this.getInputData());
  54. }.bind(this));
  55. this.node.getFirst().addEvent("blur", function(){
  56. this.validation();
  57. }.bind(this));
  58. this.node.getFirst().addEvent("keyup", function(){
  59. this.validationMode();
  60. }.bind(this));
  61. },
  62. _afterLoaded: function(){
  63. if (!this.readonly){
  64. this.loadDescription();
  65. }
  66. },
  67. loadDescription: function(){
  68. var v = this._getBusinessData();
  69. if (!v){
  70. if (this.json.description){
  71. var size = this.node.getFirst().getSize();
  72. var w = size.x-23;
  73. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  74. this.descriptionNode.setStyles({
  75. "width": ""+w+"px",
  76. "height": ""+size.y+"px",
  77. "line-height": ""+size.y+"px"
  78. });
  79. this.setDescriptionEvent();
  80. }
  81. }
  82. },
  83. setDescriptionEvent: function(){
  84. if (this.descriptionNode){
  85. if (COMMON.Browser.Platform.name==="ios"){
  86. this.descriptionNode.addEvents({
  87. "click": function(){
  88. this.descriptionNode.setStyle("display", "none");
  89. this.node.getFirst().focus();
  90. }.bind(this)
  91. });
  92. }else if (COMMON.Browser.Platform.name==="android"){
  93. this.descriptionNode.addEvents({
  94. "click": function(){
  95. this.descriptionNode.setStyle("display", "none");
  96. this.node.getFirst().focus();
  97. }.bind(this)
  98. });
  99. }else{
  100. this.descriptionNode.addEvents({
  101. "click": function(){
  102. this.descriptionNode.setStyle("display", "none");
  103. this.node.getFirst().focus();
  104. }.bind(this)
  105. });
  106. }
  107. this.node.getFirst().addEvents({
  108. "focus": function(){
  109. this.descriptionNode.setStyle("display", "none");
  110. }.bind(this),
  111. "blur": function(){
  112. if (!this.node.getFirst().get("value")) this.descriptionNode.setStyle("display", "block");
  113. }.bind(this)
  114. });
  115. }
  116. }
  117. });