appmobile.js 19 KB

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