Subform.js 4.7 KB

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