SourceText.js 1.9 KB

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