app.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. layout = window.layout || {};
  2. var href = window.location.href;
  3. if (href.indexOf("debugger")!=-1) layout.debugger = true;
  4. layout.desktop = layout;
  5. COMMON.DOM.addReady(function(){
  6. COMMON.AjaxModule.load("/x_desktop/res/framework/mootools/plugin/mBox.Notice.js", null, false);
  7. COMMON.AjaxModule.load("/x_desktop/res/framework/mootools/plugin/mBox.Tooltip.js", null, false);
  8. COMMON.setContentPath("/x_desktop");
  9. COMMON.AjaxModule.load("mwf", function(){
  10. MWF.defaultPath = "/x_desktop"+MWF.defaultPath;
  11. MWF.loadLP("zh-cn");
  12. MWF.require("MWF.widget.Mask", null, false);
  13. layout.mask = new MWF.widget.Mask({"style": "desktop"});
  14. layout.mask.load();
  15. MWF.require("MWF.xDesktop.Layout", function(){
  16. MWF.require("MWF.xDesktop.Authentication", null, false);
  17. MWF.xDesktop.requireApp("Common", "", null, false);
  18. (function(){
  19. layout.requireApp = function(appNames, callback, clazzName){
  20. var appPath = appNames.split(".");
  21. var appName = appPath[appPath.length-1];
  22. var appObject = "MWF.xApplication."+appNames;
  23. var className = clazzName || "Main";
  24. var appClass = appObject+"."+className;
  25. var appLp = appObject+".lp."+MWF.language;
  26. var baseObject = MWF.xApplication;
  27. appPath.each(function(path, i){
  28. if (i<(appPath.length-1)){
  29. baseObject[path] = baseObject[path] || {};
  30. }else {
  31. baseObject[path] = baseObject[path] || {"options": Object.clone(MWF.xApplication.Common.options)};
  32. }
  33. baseObject = baseObject[path];
  34. }.bind(this));
  35. if (!baseObject.options) baseObject.options = Object.clone(MWF.xApplication.Common.options);
  36. MWF.xDesktop.requireApp(appNames, "lp."+MWF.language, null, false);
  37. MWF.xDesktop.requireApp(appNames, clazzName, function(){
  38. if (callback) callback(baseObject);
  39. });
  40. //
  41. //MWF.require(appLp, null, false);
  42. //MWF.require(appClass, function(){
  43. // if (callback) callback(baseObject);
  44. //});
  45. };
  46. layout.openApplication = function(e, appNames, options, status){
  47. debugger;
  48. if (layout.app){
  49. layout.desktop.openBrowserApp = appNames;
  50. layout.desktop.openBrowserStatus = status;
  51. layout.desktop.openBrowserOption = options;
  52. window.open("app.html", "_blank");
  53. }else{
  54. var appPath = appNames.split(".");
  55. var appName = appPath[appPath.length-1];
  56. layout.requireApp(appNames, function(appNamespace){
  57. this.createNewApplication(e, appNamespace, appName, options, status);
  58. }.bind(this));
  59. }
  60. };
  61. layout.createNewApplication = function(e, appNamespace, appName, options, status){
  62. var app = new appNamespace["Main"](this, options);
  63. app.desktop = layout;
  64. app.inBrowser = true;
  65. app.status = status;
  66. app.load(true);
  67. var appId = appName;
  68. if (options.appId){
  69. appId = options.appId;
  70. }else{
  71. if (appNamespace.options.multitask) appId = appId+"-"+(new MWF.widget.UUID());
  72. }
  73. app.appId = appId;
  74. layout.app = app;
  75. };
  76. layout.load = function(){
  77. this.isAuthentication(function(){
  78. //layout.desktop = layout;
  79. layout.apps = [];
  80. this.node = $("layout");
  81. var topWindow = window.opener;
  82. if (topWindow){
  83. var appName = topWindow.layout.desktop.openBrowserApp;
  84. var status = topWindow.layout.desktop.openBrowserStatus;
  85. var option = topWindow.layout.desktop.openBrowserOption;
  86. layout.openApplication(null, appName, option||{}, status);
  87. //topWindow.layout.desktop.openBrowserApp = null;
  88. //topWindow.layout.desktop.openBrowserStatus = null;
  89. //topWindow.layout.desktop.openBrowserOption = null;
  90. }
  91. layout.mask.hide();
  92. }.bind(this));
  93. };
  94. //layout.getServiceAddress = function(callback){
  95. // var host = layout.config.center.host || window.location.hostname;
  96. // var port = layout.config.center.port;
  97. // var uri = "";
  98. // if (!port || port=="80"){
  99. // uri = "http://"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  100. // }else{
  101. // uri = "http://"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  102. // }
  103. // var currenthost = window.location.hostname;
  104. // uri = uri.replace(/{source}/g, currenthost);
  105. // //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  106. // MWF.restful("get", uri, null, function(json){
  107. // this.serviceAddressList = json.data;
  108. // if (callback) callback();
  109. // }.bind(this));
  110. //};
  111. layout.getServiceAddress = function(callback){
  112. if (typeOf(layout.config.center)=="object"){
  113. this.getServiceAddressConfigObject(callback);
  114. }else if (typeOf(layout.config.center)=="array"){
  115. this.getServiceAddressConfigArray(callback);
  116. }
  117. };
  118. layout.getServiceAddressConfigArray = function(callback) {
  119. var requests = [];
  120. layout.config.center.each(function(center){
  121. requests.push(
  122. this.getServiceAddressConfigObject(function(){
  123. requests.each(function(res){
  124. if (res.isRunning()){res.cancel();}
  125. });
  126. if (callback) callback();
  127. }.bind(this), center)
  128. );
  129. }.bind(this));
  130. };
  131. layout.getServiceAddressConfigObject = function(callback, center){
  132. var centerConfig = center;
  133. if (!centerConfig) centerConfig = layout.config.center;
  134. var host = centerConfig.host || window.location.hostname;
  135. var port = centerConfig.port;
  136. var uri = "";
  137. if (!port || port=="80"){
  138. uri = "http://"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  139. }else{
  140. uri = "http://"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  141. }
  142. var currenthost = window.location.hostname;
  143. uri = uri.replace(/{source}/g, currenthost);
  144. //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  145. return MWF.restful("get", uri, null, function(json){
  146. this.serviceAddressList = json.data;
  147. this.centerServer = center;
  148. if (callback) callback();
  149. }.bind(this));
  150. };
  151. layout.isAuthentication = function(callback){
  152. this.authentication = new MWF.xDesktop.Authentication({
  153. "onLogin": layout.load.bind(layout)
  154. });
  155. var returnValue = true;
  156. this.authentication.isAuthenticated(function(json){
  157. this.user = json.data;
  158. this.session = {};
  159. this.session.user = json.data;
  160. if (callback) callback();
  161. }.bind(this), function(){
  162. this.authentication.loadLogin(this.node);
  163. returnValue = false;
  164. }.bind(this));
  165. return returnValue;
  166. };
  167. MWF.getJSON("res/config/config.json", function(config){
  168. layout.config = config;
  169. layout.getServiceAddress(function(){
  170. layout.load();
  171. });
  172. });
  173. })();
  174. });
  175. });
  176. });