SourceText.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /** @class SourceText 数据文本组件。
  3. * @o2cn 数据文本
  4. * @example
  5. * //可以在脚本中获取该组件
  6. * //方法1:
  7. * var sourceText = this.form.get("fieldId"); //获取组件
  8. * //方法2
  9. * var sourceText = this.target; //在组件本身的脚本中获取
  10. * @extends MWF.xApplication.process.Xform.$Module
  11. * @o2category FormComponents
  12. * @o2range {Portal}
  13. * @hideconstructor
  14. */
  15. MWF.xApplication.process.Xform.SourceText = MWF.APPSourceText = new Class({
  16. Extends: MWF.APP$Module,
  17. _loadUserInterface: function(){
  18. /**
  19. * @ignore
  20. * @member parentLine
  21. * @memberOf MWF.xApplication.process.Xform.SourceText#
  22. */
  23. this._loadJsonData();
  24. },
  25. _getSource: function(){
  26. var parent = this.node.getParent();
  27. while(parent && (parent.get("MWFtype")!="source" && parent.get("MWFtype")!="subSource" && parent.get("MWFtype")!="subSourceItem")) parent = parent.getParent();
  28. return (parent) ? parent.retrieve("module") : null;
  29. },
  30. _loadJsonData: function(){
  31. this.node.set("text", "");
  32. this.source = this._getSource();
  33. if (this.source){
  34. if (this.source.data){
  35. COMMON.AjaxModule.load("JSONTemplate", function(){
  36. this.template = new Template();
  37. this.text = this.template.substitute("{"+this.json.jsonPath+"}", this.source.data);
  38. if (this.json.jsonText){
  39. if (this.json.jsonText.code){
  40. this.text = this.form.Macro.exec(this.json.jsonText.code, this);
  41. if( typeOf(this.text) === "string" )this.node.set("text", this.text);
  42. }else{
  43. this.node.set("text", this.text);
  44. }
  45. }else{
  46. this.node.set("text", this.text);
  47. }
  48. }.bind(this));
  49. }
  50. }
  51. }
  52. });