index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. //layout.session.user = {};
  8. layout.desktop = layout;
  9. var uri = new URI(href);
  10. var appNames = "portal.Portal";
  11. var id = "17d2cc06-b28a-4e40-b588-edf72f84a011"; //uri.getData("id");
  12. var page = uri.getData("page");
  13. if( !page )page = "fade60f4-b4c9-446d-8ff3-9f1e0da4813c";
  14. var statusObj = {"portalId": id, "pageId": page};
  15. var options = null;
  16. layout.desktop = layout;
  17. COMMON.DOM.addReady(function(){
  18. COMMON.AjaxModule.load("/x_desktop/res/framework/mootools/plugin/mBox.Notice.js", null, false);
  19. COMMON.AjaxModule.load("/x_desktop/res/framework/mootools/plugin/mBox.Tooltip.js", null, false);
  20. COMMON.setContentPath("/x_desktop");
  21. //COMMON.AjaxModule.load("ie_adapter", function(){
  22. COMMON.AjaxModule.load("mwf", function(){
  23. MWF.defaultPath = "/x_desktop"+MWF.defaultPath;
  24. MWF.loadLP("zh-cn");
  25. // MWF.require("MWF.widget.Mask", null, false);
  26. // layout.mask = new MWF.widget.Mask({"style": "desktop"});
  27. // layout.mask.load();
  28. MWF.require("MWF.xDesktop.Layout", function(){
  29. MWF.xDesktop.requireApp("Common", "", null, false);
  30. MWF.require("MWF.xDesktop.Authentication", null, false);
  31. MWF.xDesktop.Authentication2 = new Class({
  32. Extends : MWF.xDesktop.Authentication,
  33. openLoginForm: function( options, callback ){
  34. var opt = Object.merge( this.popupOptions || {}, this.options.loginOptions || {}, options || {}, {
  35. onPostOk : function(json){
  36. if( callback )callback(json);
  37. if( this.postLogin )this.postLogin( json );
  38. this.fireEvent("postOk",json)
  39. }.bind(this)
  40. });
  41. var form = new MWF.xDesktop.Authentication.LoginForm(this, {}, opt, this.popupPara );
  42. form.create();
  43. }
  44. });
  45. (function(){
  46. layout.requireApp = function(appNames, callback, clazzName){
  47. var appPath = appNames.split(".");
  48. var appName = appPath[appPath.length-1];
  49. var appObject = "MWF.xApplication."+appNames;
  50. var className = clazzName || "Main";
  51. var appClass = appObject+"."+className;
  52. var appLp = appObject+".lp."+MWF.language;
  53. var baseObject = MWF.xApplication;
  54. appPath.each(function(path, i){
  55. if (i<(appPath.length-1)){
  56. baseObject[path] = baseObject[path] || {};
  57. }else {
  58. baseObject[path] = baseObject[path] || {"options": Object.clone(MWF.xApplication.Common.options)};
  59. }
  60. baseObject = baseObject[path];
  61. }.bind(this));
  62. if (!baseObject.options) baseObject.options = Object.clone(MWF.xApplication.Common.options);
  63. //MWF.xDesktop.requireApp(appNames, "lp."+MWF.language, null, false);
  64. MWF.xDesktop.requireApp(appNames, "lp."+MWF.language, {
  65. "onRequestFailure": function(){
  66. MWF.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
  67. }.bind(this),
  68. "onSuccess": function(){}.bind(this)
  69. }, false);
  70. MWF.xDesktop.requireApp(appNames, clazzName, function(){
  71. if (callback) callback(baseObject);
  72. });
  73. //
  74. //MWF.require(appLp, null, false);
  75. //MWF.require(appClass, function(){
  76. // if (callback) callback(baseObject);
  77. //});
  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. window.open("/x_desktop/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.refreshApp = function(app){
  109. var status = app.recordStatus();
  110. var topWindow = window.opener;
  111. if (topWindow){
  112. topWindow.layout.desktop.openBrowserStatus = status;
  113. var appName = topWindow.layout.desktop.openBrowserApp || appNames;
  114. var m_status = status;
  115. var option = topWindow.layout.desktop.openBrowserOption || options;
  116. window.location.reload();
  117. }else{
  118. statusStr = encodeURIComponent(JSON.encode(status));
  119. var port = uri.get("port");
  120. var url = uri.get("scheme")+"://"+uri.get("host")+((port) ? ":"+port+"" : "")+uri.get("directory")+uri.get("file")+"?app="+appNames+"&status="+statusStr;
  121. window.location = url;
  122. }
  123. //layout.openApplication(null, appName, option||{}, m_status);
  124. };
  125. layout.load = function(){
  126. debugger;
  127. this.isAuthentication(function(){
  128. layout.desktop = layout;
  129. layout.apps = [];
  130. this.node = $("layout");
  131. var topWindow = window.opener;
  132. if (topWindow){
  133. var appName = topWindow.layout.desktop.openBrowserApp || appNames;
  134. var m_status = topWindow.layout.desktop.openBrowserStatus || statusObj;
  135. var option = topWindow.layout.desktop.openBrowserOption || options;
  136. layout.openApplication(null, appName, option||{}, m_status);
  137. //topWindow.layout.desktop.openBrowserApp = null;
  138. //topWindow.layout.desktop.openBrowserStatus = null;
  139. //topWindow.layout.desktop.openBrowserOption = null;
  140. }else{
  141. var appName = appNames;
  142. var m_status = statusObj;
  143. var option = options;
  144. layout.openApplication(null, appName, option||{}, m_status);
  145. }
  146. if (layout.mask) layout.mask.hide();
  147. }.bind(this));
  148. };
  149. layout.isAuthentication = function(callback){
  150. this.authentication = new MWF.xDesktop.Authentication2({
  151. loginOptions : {
  152. "title" : "浙江省机关事务管理局"
  153. },
  154. "onLogin": layout.load.bind(layout)
  155. });
  156. var returnValue = true;
  157. this.authentication.isAuthenticated(function(json){
  158. this.user = json.data;
  159. this.session = {};
  160. this.session.user = json.data;
  161. $("appContent").setStyle("display","");
  162. $("loginBackground").setStyle("display","none");
  163. if (callback) callback();
  164. }.bind(this), function(){
  165. this.authentication.loadLogin(document.body);
  166. //if (layout.mask) layout.mask.hide();
  167. returnValue = false;
  168. }.bind(this));
  169. return returnValue;
  170. };
  171. MWF.getJSON("/x_desktop/res/config/config.json", function(config){
  172. layout.config = config;
  173. if (layout.config.app_protocol=="auto"){
  174. layout.config.app_protocol = window.location.protocol;
  175. }
  176. MWF.xDesktop.getServiceAddress(layout.config, function(service, center){
  177. layout.serviceAddressList = service;
  178. layout.centerServer = center;
  179. layout.load();
  180. }.bind(this));
  181. //layout.getServiceAddress(function(){
  182. // layout.load();
  183. //});
  184. });
  185. })();
  186. });
  187. });
  188. //}.bind(this));
  189. });