Label.js 3.5 KB

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