Subform.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. MWF.xDesktop.requireApp("process.Xform", "Subform", null, false);
  2. MWF.xApplication.cms.Xform.Subform = MWF.CMSSubform = new Class({
  3. Extends: MWF.APPSubform,
  4. getSubform: function(callback){
  5. if (this.json.subformType==="script"){
  6. if (this.json.subformScript && this.json.subformScript.code){
  7. var data = this.form.Macro.exec(this.json.subformScript.code, this);
  8. if (data){
  9. var formName, app;
  10. if( typeOf( data ) === "string" ){
  11. formName = data;
  12. }else{
  13. if( data.application )app = data.application;
  14. if( data.subform )formName = data.subform;
  15. }
  16. if( formName ){
  17. if( !app )app = this.form.businessData.document.appId || this.form.businessData.document.application;
  18. MWF.Actions.get("x_cms_assemble_control").getFormWithColumn(formName, app, function(json){
  19. this.getSubformData(json.data);
  20. if (callback) callback();
  21. }.bind(this));
  22. }else{
  23. if (callback) callback();
  24. }
  25. }else{
  26. if (callback) callback();
  27. }
  28. }
  29. }else{
  30. if (this.json.subformSelected && this.json.subformSelected!=="none"){
  31. var subformData = (this.form.app.relatedFormMap) ? this.form.app.relatedFormMap[this.json.subformSelected] : null;
  32. if (subformData) {
  33. this.getSubformData({"data": subformData.data});
  34. if (callback) callback();
  35. } else {
  36. var app;
  37. if( this.json.subformAppSelected ){
  38. app = this.json.subformAppSelected;
  39. }else{
  40. app = this.form.businessData.document.appId || this.form.businessData.document.application;
  41. }
  42. MWF.Actions.get("x_cms_assemble_control").getFormWithColumn(this.json.subformSelected, app, function(json){
  43. this.getSubformData(json.data);
  44. if (callback) callback();
  45. }.bind(this));
  46. }
  47. }else{
  48. if (callback) callback();
  49. }
  50. }
  51. //if (this.json.subformType==="script"){
  52. // if (this.json.subformScript.code){
  53. // var formNome = this.form.Macro.exec(this.json.subformScript.code, this);
  54. // if (formNome){
  55. // MWF.Actions.get("x_cms_assemble_control").getForm(formNome, function(json){
  56. // this.getSubformData(json.data);
  57. // if (callback) callback();
  58. // }.bind(this));
  59. // }
  60. // }
  61. //}else{
  62. // if (this.json.subformSelected && this.json.subformSelected!=="none"){
  63. // MWF.Actions.get("x_cms_assemble_control").getForm(this.json.subformSelected, function(json){
  64. // this.getSubformData(json.data);
  65. // if (callback) callback();
  66. // }.bind(this));
  67. // }else{
  68. // if (callback) callback();
  69. // }
  70. //}
  71. },
  72. getSubformData: function (data) {
  73. if (!data || typeOf(data) !== "object") return;
  74. var subformDataStr = null;
  75. if ( this.form.json.mode !== "Mobile" && !layout.mobile){
  76. subformDataStr = data.data;
  77. }else{
  78. subformDataStr = data.mobileData;
  79. }
  80. this.subformData = null;
  81. if (subformDataStr) {
  82. if( this.form.isParseLanguage ) {
  83. var jsonStr = o2.bindJson(MWF.decodeJsonString(subformDataStr), {"lp": MWF.xApplication.process.Xform.LP.form});
  84. this.subformData = JSON.decode(jsonStr);
  85. }else{
  86. this.subformData = JSON.decode(MWF.decodeJsonString(subformDataStr));
  87. }
  88. this.subformData.updateTime = data.updateTime;
  89. }
  90. }
  91. });