Label.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /** @class Label 文本组件。
  3. * @example
  4. * //可以在脚本中获取该组件
  5. * //方法1:
  6. * var attachment = this.form.get("name"); //获取组件
  7. * //方法2
  8. * var attachment = this.target; //在组件事件脚本中获取
  9. * @extends MWF.xApplication.process.Xform.$Module
  10. * @category FormComponents
  11. * @hideconstructor
  12. */
  13. MWF.xApplication.process.Xform.Label = MWF.APPLabel = new Class(
  14. /** @lends MWF.xApplication.process.Xform.Label# */
  15. {
  16. Implements: [Events],
  17. Extends: MWF.APP$Module,
  18. _loadUserInterface: function(){
  19. if (this.json.valueType == "text"){
  20. this.node.set("text", this.json.text || "");
  21. }
  22. if (this.json.valueType == "script"){
  23. var code = (this.json.script) ? this.json.script.code : "";
  24. if (code){
  25. var value = this.form.Macro.exec(code, this);
  26. this._setNodeText(value);
  27. //this.node.set("text", this.form.Macro.exec(code, this) || "");
  28. }
  29. }
  30. if (this.json.prefixIcon || this.json.suffixIcon){
  31. var text = this.node.get("text");
  32. this.node.empty();
  33. var tNode = new Element("div", {"styles": {
  34. "margin-left": (this.json.prefixIcon) ? "20px" : "0px",
  35. "margin-right": (this.json.suffixIcon) ? "20px" : "0px",
  36. "height": "100%"
  37. }, "text": text}).inject(this.node);
  38. if (this.json.prefixIcon){
  39. var node = new Element("div", {"styles": {
  40. "float": "left",
  41. "width": "20px",
  42. "height": ""+this.node.getSize().y+"px",
  43. "background": "url("+this.json.prefixIcon+") center center no-repeat"
  44. }}).inject(tNode, "before");
  45. }
  46. if (this.json.suffixIcon){
  47. var node = new Element("div", {"styles": {
  48. "float": "right",
  49. "width": "20px",
  50. "height": ""+this.node.getSize().y+"px",
  51. "background": "url("+this.json.suffixIcon+") center center no-repeat"
  52. }}).inject(tNode, "before");
  53. }
  54. }
  55. },
  56. _setNodeText: function(value){
  57. if (value && value.isAG){
  58. value.addResolve(function(v){
  59. this._setNodeText(v);
  60. }.bind(this));
  61. }else{
  62. o2.promiseAll(value).then(function(v){
  63. this.node.set("text", v || "");
  64. }.bind(this), function(){});
  65. //this.node.set("text", value || "");
  66. }
  67. },
  68. /**当参数为Promise的时候,请参考文档: {@link https://www.yuque.com/o2oa/ixsnyt/ws07m0|使用Promise处理表单异步}<br/>
  69. * @summary 为组件设置文本,该文本不会被保存到后台。
  70. * @param text{String|Promise} .
  71. * @example
  72. * this.form.get("fieldName").setText("test"); //赋文本值
  73. * @example
  74. * //使用Promise
  75. * var field = this.form.get("fieldName");
  76. * var dict = new this.Dict("test"); //test为数据字典名称
  77. * var promise = dict.get("tools", true); //异步使用数据字典的get方法时返回Promise,参数true表示异步
  78. * field.setText( promise );
  79. */
  80. setText: function(text){
  81. if (!!text){
  82. o2.promiseAll(text).then(function(v){
  83. this.node.set("text", v || "");
  84. }.bind(this), function(){});
  85. }else{
  86. this.node.set("text", v || "");
  87. }
  88. //this.node.set("text", text);
  89. }
  90. });