Label.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.Label = MWF.APPLabel = new Class({
  3. Implements: [Events],
  4. Extends: MWF.APP$Module,
  5. _loadUserInterface: function(){
  6. if (this.json.valueType == "text"){
  7. this.node.set("text", this.json.text || "");
  8. }
  9. if (this.json.valueType == "script"){
  10. var code = (this.json.script) ? this.json.script.code : "";
  11. if (code){
  12. var value = this.form.Macro.exec(code, this);
  13. this._setNodeText(value);
  14. //this.node.set("text", this.form.Macro.exec(code, this) || "");
  15. }
  16. }
  17. if (this.json.prefixIcon || this.json.suffixIcon){
  18. var text = this.node.get("text");
  19. this.node.empty();
  20. var tNode = new Element("div", {"styles": {
  21. "margin-left": (this.json.prefixIcon) ? "20px" : "0px",
  22. "margin-right": (this.json.suffixIcon) ? "20px" : "0px",
  23. "height": "100%"
  24. }, "text": text}).inject(this.node);
  25. if (this.json.prefixIcon){
  26. var node = new Element("div", {"styles": {
  27. "float": "left",
  28. "width": "20px",
  29. "height": ""+this.node.getSize().y+"px",
  30. "background": "url("+this.json.prefixIcon+") center center no-repeat"
  31. }}).inject(tNode, "before");
  32. }
  33. if (this.json.suffixIcon){
  34. var node = new Element("div", {"styles": {
  35. "float": "right",
  36. "width": "20px",
  37. "height": ""+this.node.getSize().y+"px",
  38. "background": "url("+this.json.suffixIcon+") center center no-repeat"
  39. }}).inject(tNode, "before");
  40. }
  41. }
  42. },
  43. _setNodeText: function(value){
  44. if (value && value.isAG){
  45. value.addResolve(function(v){
  46. this._setNodeText(v);
  47. }.bind(this));
  48. }else{
  49. o2.promiseAll(value).then(function(v){
  50. this.node.set("text", v || "");
  51. }.bind(this));
  52. //this.node.set("text", value || "");
  53. }
  54. },
  55. setText: function(text){
  56. o2.promiseAll(text).then(function(v){
  57. this.node.set("text", v || "");
  58. }.bind(this));
  59. //this.node.set("text", text);
  60. }
  61. });