appmobile.js 19 KB

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