Subform.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.Subform = MWF.APPSubform = new Class({
  3. Extends: MWF.APP$Module,
  4. _loadUserInterface: function(){
  5. this.node.empty();
  6. this.getSubform(function(){
  7. if (this.subformData){
  8. this.loadSubform();
  9. }
  10. }.bind(this));
  11. },
  12. reload: function(){
  13. this.node.empty();
  14. this.getSubform(function(){
  15. if (this.subformData){
  16. this.loadSubform();
  17. }
  18. }.bind(this));
  19. },
  20. loadCss: function(){
  21. if (this.subformData.json.css && this.subformData.json.css.code){
  22. var cssText = this.form.parseCSS(this.subformData.json.css.code);
  23. var rex = new RegExp("(.+)(?=\\{)", "g");
  24. var match;
  25. var id = this.form.json.id.replace(/\-/g, "");
  26. while ((match = rex.exec(cssText)) !== null) {
  27. var prefix = ".css" + id + " ";
  28. var rule = prefix + match[0];
  29. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  30. rex.lastIndex = rex.lastIndex + prefix.length;
  31. }
  32. var styleNode = $("style"+this.form.json.id);
  33. if (!styleNode){
  34. var styleNode = document.createElement("style");
  35. styleNode.setAttribute("type", "text/css");
  36. styleNode.id="style"+this.form.json.id;
  37. styleNode.inject(this.form.container, "before");
  38. }
  39. if(styleNode.styleSheet){
  40. var setFunc = function(){
  41. styleNode.styleSheet.cssText += cssText;
  42. };
  43. if(styleNode.styleSheet.disabled){
  44. setTimeout(setFunc, 10);
  45. }else{
  46. setFunc();
  47. }
  48. }else{
  49. var cssTextNode = document.createTextNode(cssText);
  50. styleNode.appendChild(cssTextNode);
  51. }
  52. }
  53. },
  54. loadSubform: function(){
  55. if (this.subformData){
  56. //this.form.addEvent("postLoad", function(){
  57. this.loadCss();
  58. this.node.set("html", this.subformData.html);
  59. Object.each(this.subformData.json.moduleList, function(module, key){
  60. var formKey = key;
  61. if (this.form.json.moduleList[key]){
  62. formKey = this.json.id+"_"+key;
  63. var moduleNode = this.node.getElement("#"+key);
  64. if (moduleNode) moduleNode.set("id", formKey);
  65. module.id = formKey;
  66. }
  67. this.form.json.moduleList[formKey] = module;
  68. }.bind(this));
  69. var moduleNodes = this.form._getModuleNodes(this.node);
  70. moduleNodes.each(function(node){
  71. if (node.get("MWFtype")!=="form"){
  72. var json = this.form._getDomjson(node);
  73. var module = this.form._loadModule(json, node);
  74. this.form.modules.push(module);
  75. }
  76. }.bind(this));
  77. //}.bind(this));
  78. }
  79. },
  80. getSubform: function(callback){
  81. if (this.json.subformType==="script"){
  82. if (this.json.subformScript.code){
  83. var formNome = this.form.Macro.exec(this.json.subformScript.code, this);
  84. if (formNome){
  85. var app = (this.form.businessData.work || this.form.businessData.workCompleted).application;
  86. MWF.Actions.get("x_processplatform_assemble_surface").getForm(formNome, app, function(json){
  87. this.getSubformData(json.data);
  88. if (callback) callback();
  89. }.bind(this));
  90. }
  91. }
  92. }else{
  93. if (this.json.subformSelected && this.json.subformSelected!=="none"){
  94. var app = (this.form.businessData.work || this.form.businessData.workCompleted).application;
  95. MWF.Actions.get("x_processplatform_assemble_surface").getForm(this.json.subformSelected, app, function(json){
  96. this.getSubformData(json.data);
  97. if (callback) callback();
  98. }.bind(this));
  99. }else{
  100. if (callback) callback();
  101. }
  102. }
  103. },
  104. getSubformData: function(data){
  105. var subformDataStr = null;
  106. if (this.form.options.mode !== "Mobile"){
  107. subformDataStr = data.data;
  108. }else{
  109. subformDataStr = data.mobileData;
  110. }
  111. this.subformData = null;
  112. if (subformDataStr){
  113. this.subformData = JSON.decode(MWF.decodeJsonString(subformDataStr));
  114. this.subformData.updateTime = data.updateTime;
  115. }
  116. }
  117. });