appmobile.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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.mobile = true;
  7. layout.desktop = layout;
  8. layout.desktop.session = {};
  9. var uri = new URI(href);
  10. var appNames = uri.getData("app");
  11. var optionsStr = (uri.getData("option"));
  12. var statusStr = (uri.getData("status"));
  13. var options = (optionsStr) ? JSON.decode(optionsStr) : null;
  14. var statusObj = (statusStr) ? JSON.decode(statusStr) : null;
  15. COMMON.DOM.addReady(function(){
  16. COMMON.AjaxModule.load("/x_desktop/res/framework/mootools/plugin/mBox.Notice.js", null, false);
  17. COMMON.AjaxModule.load("/x_desktop/res/framework/mootools/plugin/mBox.Tooltip.js", null, false);
  18. COMMON.setContentPath("/x_desktop");
  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.openApplication = function(e, appNames, options, statusObj){
  63. if (layout.app){
  64. layout.desktop.openBrowserApp = appNames;
  65. layout.desktop.openBrowserStatus = statusObj;
  66. layout.desktop.openBrowserOption = options;
  67. var optionsStr = JSON.encode(options);
  68. var statusStr = JSON.encode(statusObj);
  69. //window.open("appMobile.html", "_blank");
  70. //layout.openApplication(null, appNames, option||{}, m_status);
  71. var title = options.docTitle || "";
  72. switch (appNames){
  73. case "process.Work":
  74. if (window.o2 && window.o2.openO2Work){
  75. if( options.workId ){
  76. window.o2.openO2Work(options.workId, "", title);
  77. }else if( options.workCompletedId ){
  78. window.o2.openO2Work("", options.workCompletedId, title);
  79. }
  80. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Work){
  81. if( options.workId ){
  82. window.webkit.messageHandlers.openO2Work.postMessage({"work":options.workId, "workCompleted":"", "title":title});
  83. }else if( options.workCompletedId ){
  84. window.webkit.messageHandlers.openO2Work.postMessage({"work":"", "workCompleted":options.workCompletedId, "title":title});
  85. }
  86. }else{
  87. var uri = new URI(window.location.href);
  88. var redirectlink = uri.getData("redirectlink");
  89. if( !redirectlink ){
  90. redirectlink = encodeURIComponent(locate.pathname + locate.search);
  91. }else{
  92. redirectlink = encodeURIComponent(redirectlink);
  93. }
  94. if( options.workId ){
  95. window.location = "workmobilewithaction.html?workid="+options.workId+"&redirectlink="+redirectlink;
  96. }else if( options.workCompletedId ){
  97. window.location = "workmobilewithaction.html?workcompletedid="+options.workCompletedId+"&redirectlink="+redirectlink;
  98. }
  99. }
  100. break;
  101. case "cms.Document":
  102. if (window.o2 && window.o2.openO2CmsDocument){
  103. window.o2.openO2CmsDocument(options.documentId, title);
  104. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsDocument){
  105. window.webkit.messageHandlers.openO2CmsDocument.postMessage({"docId":options.documentId,"docTitle":title});
  106. }else{
  107. window.location = "appMobile.html?app="+appNames+"&option="+(optionsStr || "")+"&status="+(statusStr || "");
  108. }
  109. break;
  110. case "cms.Module":
  111. if (window.o2 && window.o2.openO2CmsApplication){
  112. window.o2.openO2CmsApplication(options.columnId, title);
  113. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsApplication){
  114. window.webkit.messageHandlers.openO2CmsApplication.postMessage(options.columnId);
  115. }else{
  116. window.location = "appMobile.html?app="+appNames+"&option="+(optionsStr || "")+"&status="+(statusStr || "");
  117. }
  118. break;
  119. case "Meeting":
  120. if (window.o2 && window.o2.openO2Meeting){
  121. window.o2.openO2Meeting("");
  122. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Meeting){
  123. window.webkit.messageHandlers.openO2Meeting.postMessage("");
  124. }else{
  125. window.location = "appMobile.html?app="+appNames+"&option="+(optionsStr || "")+"&status="+(statusStr || "");
  126. }
  127. break;
  128. case "Calendar":
  129. if (window.o2 && window.o2.openO2Calendar){
  130. window.o2.openO2Calendar("");
  131. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Calendar){
  132. window.webkit.messageHandlers.openO2Calendar.postMessage("");
  133. }else{
  134. window.location = "appMobile.html?app="+appNames+"&option="+(optionsStr || "")+"&status="+(statusStr || "");
  135. }
  136. break;
  137. case "process.TaskCenter":
  138. var tab = ((options && options.navi) ? options.navi : "task").toLowerCase();
  139. if (tab==="done") tab = "taskCompleted";
  140. if (tab==="readed") tab = "readCompleted";
  141. if (window.o2 && window.o2.openO2WorkSpace){
  142. window.o2.openO2WorkSpace(tab);
  143. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2WorkSpace){
  144. window.webkit.messageHandlers.openO2WorkSpace.postMessage(tab);
  145. }else{
  146. window.location = "appMobile.html?app="+appNames+"&option="+(optionsStr || "")+"&status="+(statusStr || "");
  147. }
  148. break;
  149. default:
  150. window.location = "appMobile.html?app="+appNames+"&option="+(optionsStr || "")+"&status="+(statusStr || "");
  151. }
  152. // if (appNames === "process.Work"){
  153. // var uri = new URI(window.location.href);
  154. // var redirectlink = uri.getData("redirectlink");
  155. // if( !redirectlink ){
  156. // redirectlink = encodeURIComponent(locate.pathname + locate.search);
  157. // }else{
  158. // redirectlink = encodeURIComponent(redirectlink);
  159. // }
  160. // if( options.workId ){
  161. // window.location = "workmobilewithaction.html?workid="+options.workId+"&redirectlink="+redirectlink;
  162. // }else if( options.workCompletedId ){
  163. // window.location = "workmobilewithaction.html?workcompletedid="+options.workCompletedId+"&redirectlink="+redirectlink;
  164. // }
  165. // }else{
  166. // window.location = "appMobile.html?app="+appNames+"&option="+(optionsStr || "")+"&status="+(statusStr || "");
  167. // }
  168. //window.location = "workmobilewithaction.html?workid="+options.workId;
  169. }else{
  170. var appPath = appNames.split(".");
  171. var appName = appPath[appPath.length-1];
  172. layout.requireApp(appNames, function(appNamespace){
  173. this.createNewApplication(e, appNamespace, appName, options, statusObj);
  174. }.bind(this));
  175. }
  176. };
  177. layout.createNewApplication = function(e, appNamespace, appName, options, statusObj){
  178. var app = new appNamespace["Main"](this, options);
  179. app.desktop = layout;
  180. app.inBrowser = true;
  181. app.status = statusObj;
  182. app.load(true);
  183. var appId = appName;
  184. if (options.appId){
  185. appId = options.appId;
  186. }else{
  187. if (appNamespace.options.multitask) appId = appId+"-"+(new MWF.widget.UUID());
  188. }
  189. app.appId = appId;
  190. layout.app = app;
  191. };
  192. layout.load = function(){
  193. this.isAuthentication(function(){
  194. //layout.desktop = layout;
  195. layout.apps = [];
  196. this.node = $("layout");
  197. var topWindow = window.opener;
  198. if (topWindow){
  199. var appName = topWindow.layout.desktop.openBrowserApp || appNames;
  200. var m_status = topWindow.layout.desktop.openBrowserStatus || statusObj;
  201. var option = topWindow.layout.desktop.openBrowserOption || options;
  202. layout.openApplication(null, appName, option||{}, m_status);
  203. //topWindow.layout.desktop.openBrowserApp = null;
  204. //topWindow.layout.desktop.openBrowserStatus = null;
  205. //topWindow.layout.desktop.openBrowserOption = null;
  206. }else{
  207. var appName = appNames;
  208. var m_status = statusObj;
  209. var option = options;
  210. layout.openApplication(null, appName, option||{}, m_status);
  211. }
  212. if (layout.mask) layout.mask.hide();
  213. if (document.all.appContentMask) document.all.appContentMask.destroy();
  214. }.bind(this));
  215. };
  216. //layout.getServiceAddress = function(callback){
  217. // var host = layout.config.center.host || window.location.hostname;
  218. // var port = layout.config.center.port;
  219. // var uri = "";
  220. // if (!port || port=="80"){
  221. // uri = "http://"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  222. // }else{
  223. // uri = "http://"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  224. // }
  225. // var currenthost = window.location.hostname;
  226. // uri = uri.replace(/{source}/g, currenthost);
  227. // //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  228. // MWF.restful("get", uri, null, function(json){
  229. // this.serviceAddressList = json.data;
  230. // if (callback) callback();
  231. // }.bind(this));
  232. //};
  233. //layout.getServiceAddress = function(callback){
  234. // if (typeOf(layout.config.center)=="object"){
  235. // this.getServiceAddressConfigObject(callback);
  236. // }else if (typeOf(layout.config.center)=="array"){
  237. // this.getServiceAddressConfigArray(callback);
  238. // }
  239. //
  240. //};
  241. //layout.getServiceAddressConfigArray = function(callback) {
  242. // var requests = [];
  243. // layout.config.center.each(function(center){
  244. // requests.push(
  245. // this.getServiceAddressConfigObject(function(){
  246. // requests.each(function(res){
  247. // if (res.isRunning()){res.cancel();}
  248. // });
  249. // if (callback) callback();
  250. // }.bind(this), center)
  251. // );
  252. // }.bind(this));
  253. //};
  254. //layout.getServiceAddressConfigObject = function(callback, center){
  255. // var centerConfig = center;
  256. // if (!centerConfig) centerConfig = layout.config.center;
  257. // var host = centerConfig.host || window.location.hostname;
  258. // var port = centerConfig.port;
  259. // var uri = "";
  260. // if (!port || port=="80"){
  261. // uri = "http://"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  262. // }else{
  263. // uri = "http://"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  264. // }
  265. // var currenthost = window.location.hostname;
  266. // uri = uri.replace(/{source}/g, currenthost);
  267. // //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  268. // return MWF.restful("get", uri, null, function(json){
  269. // this.serviceAddressList = json.data;
  270. // this.centerServer = center;
  271. // if (callback) callback();
  272. // }.bind(this));
  273. //};
  274. layout.isAuthentication = function(callback){
  275. this.authentication = new MWF.xDesktop.Authentication({
  276. "onLogin": layout.load.bind(layout)
  277. });
  278. var returnValue = true;
  279. this.authentication.isAuthenticated(function(json){
  280. this.user = json.data;
  281. this.session = {};
  282. this.session.user = json.data;
  283. if (callback) callback();
  284. }.bind(this), function(){
  285. this.authentication.loadLogin(document.body);
  286. if (layout.mask) layout.mask.hide();
  287. if (document.all.appContentMask) document.all.appContentMask.destroy();
  288. returnValue = false;
  289. }.bind(this));
  290. return returnValue;
  291. };
  292. MWF.getJSON("res/config/config.json", function(config){
  293. layout.config = config;
  294. if (layout.config.app_protocol=="auto"){
  295. layout.config.app_protocol = window.location.protocol;
  296. }
  297. MWF.xDesktop.getServiceAddress(layout.config, function(service, center){
  298. layout.serviceAddressList = service;
  299. layout.centerServer = center;
  300. layout.load();
  301. }.bind(this));
  302. //layout.getServiceAddress(function(){
  303. // layout.load();
  304. //});
  305. });
  306. })();
  307. });
  308. });
  309. });