app.js 9.9 KB

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