appmobile.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. };
  190. layout.load = function(){
  191. this.isAuthentication(function(){
  192. //layout.desktop = layout;
  193. layout.apps = [];
  194. this.node = $("layout");
  195. var topWindow = window.opener;
  196. if (topWindow){
  197. try{
  198. var appName = topWindow.layout.desktop.openBrowserApp || appNames;
  199. var m_status = topWindow.layout.desktop.openBrowserStatus || statusObj;
  200. var option = topWindow.layout.desktop.openBrowserOption || options;
  201. layout.openApplication(null, appName, option||{}, m_status);
  202. }catch(e){
  203. var appName = appNames;
  204. var m_status = statusObj;
  205. var option = options;
  206. layout.openApplication(null, appName, option||{}, m_status);
  207. }
  208. //topWindow.layout.desktop.openBrowserApp = null;
  209. //topWindow.layout.desktop.openBrowserStatus = null;
  210. //topWindow.layout.desktop.openBrowserOption = null;
  211. }else{
  212. var appName = appNames;
  213. var m_status = statusObj;
  214. var option = options;
  215. layout.openApplication(null, appName, option||{}, m_status);
  216. }
  217. if (layout.mask) layout.mask.hide();
  218. if (document.all.appContentMask) document.all.appContentMask.destroy();
  219. }.bind(this));
  220. };
  221. //layout.getServiceAddress = function(callback){
  222. // var host = layout.config.center.host || window.location.hostname;
  223. // var port = layout.config.center.port;
  224. // var uri = "";
  225. // if (!port || port=="80"){
  226. // uri = "http://"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  227. // }else{
  228. // uri = "http://"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  229. // }
  230. // var currenthost = window.location.hostname;
  231. // uri = uri.replace(/{source}/g, currenthost);
  232. // //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  233. // MWF.restful("get", uri, null, function(json){
  234. // this.serviceAddressList = json.data;
  235. // if (callback) callback();
  236. // }.bind(this));
  237. //};
  238. //layout.getServiceAddress = function(callback){
  239. // if (typeOf(layout.config.center)=="object"){
  240. // this.getServiceAddressConfigObject(callback);
  241. // }else if (typeOf(layout.config.center)=="array"){
  242. // this.getServiceAddressConfigArray(callback);
  243. // }
  244. //
  245. //};
  246. //layout.getServiceAddressConfigArray = function(callback) {
  247. // var requests = [];
  248. // layout.config.center.each(function(center){
  249. // requests.push(
  250. // this.getServiceAddressConfigObject(function(){
  251. // requests.each(function(res){
  252. // if (res.isRunning()){res.cancel();}
  253. // });
  254. // if (callback) callback();
  255. // }.bind(this), center)
  256. // );
  257. // }.bind(this));
  258. //};
  259. //layout.getServiceAddressConfigObject = function(callback, center){
  260. // var centerConfig = center;
  261. // if (!centerConfig) centerConfig = layout.config.center;
  262. // var host = centerConfig.host || window.location.hostname;
  263. // var port = centerConfig.port;
  264. // var uri = "";
  265. // if (!port || port=="80"){
  266. // uri = "http://"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  267. // }else{
  268. // uri = "http://"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  269. // }
  270. // var currenthost = window.location.hostname;
  271. // uri = uri.replace(/{source}/g, currenthost);
  272. // //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  273. // return MWF.restful("get", uri, null, function(json){
  274. // this.serviceAddressList = json.data;
  275. // this.centerServer = center;
  276. // if (callback) callback();
  277. // }.bind(this));
  278. //};
  279. layout.isAuthentication = function(callback){
  280. this.authentication = new MWF.xDesktop.Authentication({
  281. "onLogin": layout.load.bind(layout)
  282. });
  283. var returnValue = true;
  284. this.authentication.isAuthenticated(function(json){
  285. this.user = json.data;
  286. this.session = {};
  287. this.session.user = json.data;
  288. if (callback) callback();
  289. }.bind(this), function(){
  290. this.authentication.loadLogin(document.body);
  291. if (layout.mask) layout.mask.hide();
  292. if (document.all.appContentMask) document.all.appContentMask.destroy();
  293. returnValue = false;
  294. }.bind(this));
  295. return returnValue;
  296. };
  297. MWF.getJSON("res/config/config.json", function(config){
  298. layout.config = config;
  299. if (layout.config.app_protocol=="auto"){
  300. layout.config.app_protocol = window.location.protocol;
  301. }
  302. MWF.xDesktop.getServiceAddress(layout.config, function(service, center){
  303. layout.serviceAddressList = service;
  304. layout.centerServer = center;
  305. layout.load();
  306. }.bind(this));
  307. //layout.getServiceAddress(function(){
  308. // layout.load();
  309. //});
  310. });
  311. })();
  312. });
  313. });
  314. });