Subpage.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.Subpage = MWF.APPSubpage = new Class({
  3. Extends: MWF.APP$Module,
  4. _loadUserInterface: function(){
  5. this.node.empty();
  6. this.getSubpage(function(){
  7. this.loadSubpage();
  8. }.bind(this));
  9. },
  10. reload: function(){
  11. this.node.empty();
  12. this.getSubpage(function(){
  13. this.loadSubpage();
  14. }.bind(this));
  15. },
  16. loadCss: function(){
  17. if (this.subpageData.json.css && this.subpageData.json.css.code){
  18. var cssText = this.form.parseCSS(this.subpageData.json.css.code);
  19. var rex = new RegExp("(.+)(?=\\{)", "g");
  20. var match;
  21. var id = this.form.json.id.replace(/\-/g, "");
  22. while ((match = rex.exec(cssText)) !== null) {
  23. var prefix = ".css" + id + " ";
  24. var rule = prefix + match[0];
  25. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  26. rex.lastIndex = rex.lastIndex + prefix.length;
  27. }
  28. var styleNode = $("style"+this.form.json.id);
  29. if (!styleNode){
  30. var styleNode = document.createElement("style");
  31. styleNode.setAttribute("type", "text/css");
  32. styleNode.id="style"+this.form.json.id;
  33. styleNode.inject(this.form.container, "before");
  34. }
  35. if(styleNode.styleSheet){
  36. var setFunc = function(){
  37. styleNode.styleSheet.cssText += cssText;
  38. };
  39. if(styleNode.styleSheet.disabled){
  40. setTimeout(setFunc, 10);
  41. }else{
  42. setFunc();
  43. }
  44. }else{
  45. var cssTextNode = document.createTextNode(cssText);
  46. styleNode.appendChild(cssTextNode);
  47. }
  48. }
  49. },
  50. checkSubpageNested : function( id ){
  51. if( this.parentpageIdList ){
  52. return !this.parentpageIdList.contains( id );
  53. }else{
  54. return ![ this.form.json.id ].contains( id );
  55. }
  56. },
  57. getParentpageIdList : function(){
  58. var parentpageIdList;
  59. if( this.parentpageIdList ){
  60. parentpageIdList = Array.clone( this.parentpageIdList );
  61. parentpageIdList.push( this.subpageData.json.id )
  62. }else{
  63. parentpageIdList = [ this.form.json.id, this.subpageData.json.id ];
  64. }
  65. return parentpageIdList;
  66. },
  67. loadSubpage: function(){
  68. if (this.subpageData ){
  69. if( this.checkSubpageNested( this.subpageData.json.id ) ){
  70. //this.form.addEvent("postLoad", function(){
  71. this.loadCss();
  72. this.form.subpageModules = this.form.subpageModules || {};
  73. var subpageModules = this.form.subpageModules[ this.json.id ] = {};
  74. var params = this.getPageParamenters();
  75. if( typeOf(params) === "object" && this.form.Macro && this.form.Macro.environment ){
  76. var environment = this.form.Macro.environment;
  77. environment.subpageParameters = environment.subpageParameters || {};
  78. environment.subpageParameters[ this.json.id ] = params;
  79. }
  80. this.node.set("html", this.subpageData.html);
  81. Object.each(this.subpageData.json.moduleList, function(module, key){
  82. var formKey = key;
  83. if (this.form.json.moduleList[key]){
  84. formKey = this.json.id+"_"+key;
  85. var moduleNode = this.node.getElement("#"+key);
  86. if (moduleNode) moduleNode.set("id", formKey);
  87. module.orgiginalId = key;
  88. module.id = formKey;
  89. }
  90. this.form.json.moduleList[formKey] = module;
  91. }.bind(this));
  92. var moduleNodes = this.form._getModuleNodes(this.node);
  93. moduleNodes.each(function(node){
  94. if (node.get("MWFtype")!=="form"){
  95. var _self = this;
  96. var json = this.form._getDomjson(node);
  97. var module = this.form._loadModule(json, node, function(){
  98. this.subpage = _self;
  99. this.parentpageIdList = _self.getParentpageIdList();
  100. });
  101. this.form.modules.push(module);
  102. subpageModules[ json.orgiginalId || json.id ] = module;
  103. }
  104. }.bind(this));
  105. //}.bind(this));
  106. }else{
  107. this.form.notice(MWF.xApplication.process.Xform.LP.subpageNestedError, "error");
  108. }
  109. }
  110. if( this.form.subpageLoadedCount ){
  111. this.form.subpageLoadedCount++;
  112. }else{
  113. this.form.subpageLoadedCount = 1
  114. }
  115. this.form.checkSubformLoaded();
  116. },
  117. getSubpage: function(callback){
  118. if (this.json.subpageType==="script"){
  119. if (this.json.subpageScript.code){
  120. var formNome = this.form.Macro.exec(this.json.subpageScript.code, this);
  121. if (formNome){
  122. var app = this.form.businessData.pageInfor.portal;
  123. o2.Actions.get("x_portal_assemble_surface").getPageByName(formNome, app, function(json){
  124. this.getSubpageData(json.data);
  125. if (callback) callback();
  126. }.bind(this));
  127. }else{
  128. if (callback) callback();
  129. }
  130. }
  131. }else{
  132. if (this.json.subpageSelected && this.json.subpageSelected!=="none"){
  133. var app = this.form.businessData.pageInfor.portal;
  134. o2.Actions.get("x_portal_assemble_surface").getPageByName(this.json.subpageSelected, app, function(json){
  135. this.getSubpageData(json.data);
  136. if (callback) callback();
  137. }.bind(this));
  138. }else{
  139. if (callback) callback();
  140. }
  141. }
  142. },
  143. getSubpageData: function(data){
  144. var subpageDataStr = null;
  145. if (this.form.json.mode !== "Mobile" && !layout.mobile){
  146. subpageDataStr = data.data;
  147. }else{
  148. subpageDataStr = data.mobileData;
  149. }
  150. this.subpageData = null;
  151. if (subpageDataStr){
  152. this.subpageData = JSON.decode(MWF.decodeJsonString(subpageDataStr));
  153. this.subpageData.updateTime = data.updateTime;
  154. }
  155. },
  156. getPageParamenters : function(){
  157. var params = null;
  158. if( this.json.parameterType === "map" ){
  159. params = this.json.parametersMapList;
  160. }else if( this.json.parameterType === "script" ){
  161. var code = this.json.parametersScript.code;
  162. if (code){
  163. params = this.form.Macro.exec(code, this);
  164. }
  165. }
  166. return params;
  167. }
  168. });