SourceText.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. * @category FormComponents
  11. * @hideconstructor
  12. */
  13. MWF.xApplication.process.Xform.SourceText = MWF.APPSourceText = new Class({
  14. Extends: MWF.APP$Module,
  15. _loadUserInterface: function(){
  16. this._loadJsonData();
  17. },
  18. _getSource: function(){
  19. var parent = this.node.getParent();
  20. while(parent && (parent.get("MWFtype")!="source" && parent.get("MWFtype")!="subSource" && parent.get("MWFtype")!="subSourceItem")) parent = parent.getParent();
  21. return (parent) ? parent.retrieve("module") : null;
  22. },
  23. _loadJsonData: function(){
  24. this.node.set("text", "");
  25. this.source = this._getSource();
  26. if (this.source){
  27. if (this.source.data){
  28. COMMON.AjaxModule.load("JSONTemplate", function(){
  29. this.template = new Template();
  30. this.text = this.template.substitute("{"+this.json.jsonPath+"}", this.source.data);
  31. if (this.json.jsonText){
  32. if (this.json.jsonText.code){
  33. this.text = this.form.Macro.exec(this.json.jsonText.code, this);
  34. if( typeOf(this.text) === "string" )this.node.set("text", this.text);
  35. }else{
  36. this.node.set("text", this.text);
  37. }
  38. }else{
  39. this.node.set("text", this.text);
  40. }
  41. }.bind(this));
  42. }
  43. }
  44. }
  45. });