appmobile.js 19 KB

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