Textarea.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. _loadNodeEdit: function(){
  24. var input = new Element("textarea", {"styles": {
  25. "background": "transparent",
  26. "width": "100%",
  27. "border": "0px"
  28. }});
  29. input.set(this.json.properties);
  30. var node = new Element("div", {"styles": {"ovwrflow": "hidden", "position": "relative"}}).inject(this.node, "after");
  31. input.inject(node);
  32. this.node.destroy();
  33. this.node = node;
  34. //this.node = input;
  35. this.node.set({
  36. "id": this.json.id,
  37. "MWFType": this.json.type
  38. });
  39. this.node.addEvent("change", function(){
  40. this._setBusinessData(this.getInputData());
  41. }.bind(this));
  42. this.node.getFirst().addEvent("blur", function(){
  43. this.validation();
  44. }.bind(this));
  45. this.node.getFirst().addEvent("keyup", function(){
  46. this.validationMode();
  47. }.bind(this));
  48. },
  49. _afterLoaded: function(){
  50. if (!this.readonly){
  51. this.loadDescription();
  52. }
  53. },
  54. loadDescription: function(){
  55. var v = this._getBusinessData();
  56. if (!v){
  57. if (this.json.description){
  58. var size = this.node.getFirst().getSize();
  59. var w = size.x-23;
  60. this.descriptionNode = new Element("div", {"styles": this.form.css.descriptionNode, "text": this.json.description}).inject(this.node);
  61. this.descriptionNode.setStyles({
  62. "width": ""+w+"px",
  63. "height": ""+size.y+"px",
  64. "line-height": ""+size.y+"px"
  65. });
  66. this.setDescriptionEvent();
  67. }
  68. }
  69. },
  70. setDescriptionEvent: function(){
  71. if (this.descriptionNode){
  72. if (COMMON.Browser.Platform.name==="ios"){
  73. this.descriptionNode.addEvents({
  74. "click": function(){
  75. this.descriptionNode.setStyle("display", "none");
  76. this.node.getFirst().focus();
  77. }.bind(this)
  78. });
  79. }else if (COMMON.Browser.Platform.name==="android"){
  80. this.descriptionNode.addEvents({
  81. "click": function(){
  82. this.descriptionNode.setStyle("display", "none");
  83. this.node.getFirst().focus();
  84. }.bind(this)
  85. });
  86. }else{
  87. this.descriptionNode.addEvents({
  88. "click": function(){
  89. this.descriptionNode.setStyle("display", "none");
  90. this.node.getFirst().focus();
  91. }.bind(this)
  92. });
  93. }
  94. this.node.getFirst().addEvents({
  95. "focus": function(){
  96. this.descriptionNode.setStyle("display", "none");
  97. }.bind(this),
  98. "blur": function(){
  99. if (!this.node.getFirst().get("value")) this.descriptionNode.setStyle("display", "block");
  100. }.bind(this)
  101. });
  102. }
  103. }
  104. });