base.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. layout = window.layout || {};
  2. layout.desktop = layout;
  3. var locate = window.location;
  4. layout.protocol = locate.protocol;
  5. layout.session = layout.session || {};
  6. layout.debugger = (locate.href.toString().indexOf("debugger")!==-1);
  7. layout.anonymous = (locate.href.toString().indexOf("anonymous")!==-1);
  8. o2.xApplication = o2.xApplication || {};
  9. o2.xDesktop = o2.xDesktop || {};
  10. o2.xDesktop.requireApp = function(module, clazz, callback, async){
  11. o2.requireApp(module, clazz, callback, async);
  12. };
  13. o2.addReady(function(){
  14. //兼容方法
  15. Element.implement({
  16. "makeLnk": function(options){}
  17. });
  18. var loadingNode = $("loaddingArea");
  19. var loadeds = 0;
  20. var loadCount = 15;
  21. var size = document.body.getSize();
  22. var _loadProgressBar = function(){
  23. if (loadingNode){
  24. loadeds++;
  25. var p = (loadeds/loadCount)*size.x;
  26. loadingNode.set('morph', {duration: 300}).morph({"width": ""+p+"px"});
  27. if (loadeds>=loadCount) window.setTimeout(function(){loadingNode.destroy();}, 500);
  28. }
  29. };
  30. //异步载入必要模块
  31. layout.config = null;
  32. var modules = [ "MWF.xDesktop.Common", "MWF.xAction.RestActions" ];
  33. MWF.require(modules, {
  34. "onSuccess": function(){
  35. if (layout.config) _getDistribute(function(){ _load(); });
  36. },
  37. "onEvery": function(){
  38. _loadProgressBar();
  39. }
  40. });
  41. o2.getJSON("/x_desktop/res/config/config.json", function(config){
  42. _loadProgressBar();
  43. layout.config = config;
  44. if (MWF.xDesktop.getServiceAddress) _getDistribute(function(){ _load(); });
  45. });
  46. var _getDistribute = function(callback){
  47. if (layout.config.app_protocol==="auto"){
  48. layout.config.app_protocol = window.location.protocol;
  49. }
  50. MWF.xDesktop.getServiceAddress(layout.config, function(service, center){
  51. layout.serviceAddressList = service;
  52. layout.centerServer = center;
  53. if (callback) callback();
  54. }.bind(this));
  55. };
  56. var _load = function(){
  57. var _loadApp = function(json){
  58. //用户已经登录
  59. layout.user = json.data;
  60. layout.session = {};
  61. layout.session.user = json.data;
  62. (function(layout){
  63. var _loadResource = function(callback){
  64. var isLoadedA = false;
  65. var isLoadedB = false;
  66. //var isLoadedC = false;
  67. var lp = o2.session.path+"/lp/"+o2.language+".js";
  68. var modules = [
  69. "o2.xDesktop.Dialog",
  70. "MWF.xDesktop.UserData",
  71. "MWF.xDesktop.Access",
  72. "MWF.widget.UUID",
  73. "MWF.xDesktop.Menu",
  74. "MWF.xDesktop.shortcut",
  75. "MWF.widget.PinYin",
  76. "MWF.xDesktop.Access",
  77. "MWF.xDesktop.MessageMobile"
  78. ];
  79. //MWF.xDesktop.requireApp("Common", "", null, false);
  80. var _check = function(){ if (isLoadedA && isLoadedB) if (callback) callback(); };
  81. o2.load(["/o2_lib/mootools/plugin/mBox.min.js",lp], function(){_loadProgressBar(); isLoadedA = true; _check();});
  82. o2.require("MWF.widget.Common", function(){
  83. _loadProgressBar();
  84. o2.require(modules, {
  85. "onSuccess": function(){
  86. o2.requireApp("Common", "", function(){_loadProgressBar(); isLoadedB = true; _check();})
  87. },
  88. "onEvery": function(){
  89. _loadProgressBar();
  90. }
  91. });
  92. });
  93. };
  94. var _loadContent =function(){
  95. _loadResource(function(){
  96. //window.status = window.status+layout.readys.length;
  97. while (layout.readys && layout.readys.length){
  98. layout.readys.shift().apply(window);
  99. }
  100. // for (var i=0; i<layout.readys.length; i++){
  101. // layout.readys[i].apply(window);
  102. // }
  103. });
  104. };
  105. _loadContent();
  106. })(layout);
  107. };
  108. //先判断用户是否登录
  109. MWF.Actions.get("x_organization_assemble_authentication").getAuthentication( function(json){
  110. //已经登录
  111. _loadApp( json );
  112. }.bind(this), function( json ){
  113. //允许匿名访问
  114. if( layout.anonymous ){
  115. _loadApp({
  116. user : "anonymous",
  117. session : {
  118. user : {
  119. name : "anonymous",
  120. roleList : []
  121. }
  122. }
  123. });
  124. }else{
  125. //用户未经登录
  126. //打开登录页面
  127. var _loadResource = function(callback){
  128. var isLoadedA = false;
  129. var isLoadedB = false;
  130. //var isLoadedC = false;
  131. var lp = o2.session.path+"/lp/"+o2.language+".js";
  132. var modules = [
  133. "o2.xDesktop.Dialog",
  134. "MWF.xDesktop.UserData",
  135. "MWF.xDesktop.Access",
  136. "MWF.widget.UUID",
  137. "MWF.xDesktop.Menu",
  138. "MWF.xDesktop.shortcut",
  139. "MWF.widget.PinYin",
  140. "MWF.xDesktop.Access",
  141. "MWF.xDesktop.MessageMobile"
  142. ];
  143. //MWF.xDesktop.requireApp("Common", "", null, false);
  144. var _check = function(){ if (isLoadedA && isLoadedB) if (callback) callback(); };
  145. o2.load(["/o2_lib/mootools/plugin/mBox.min.js",lp], function(){_loadProgressBar(); isLoadedA = true; _check();});
  146. o2.require("MWF.widget.Common", function(){
  147. _loadProgressBar();
  148. o2.require(modules, {
  149. "onSuccess":function(){
  150. o2.requireApp("Common", "", function(){isLoadedB = true; _check();})
  151. },
  152. "onEvery": function(){
  153. _loadProgressBar();
  154. }
  155. });
  156. });
  157. };
  158. _loadResource(function(){
  159. layout.openLogin();
  160. });
  161. }
  162. });
  163. layout.openLogin = function(){
  164. MWF.require("MWF.widget.Common", null, false);
  165. MWF.require("MWF.xDesktop.Authentication", function(){
  166. var authentication = new MWF.xDesktop.Authentication({
  167. "onLogin": _load.bind(layout)
  168. });
  169. authentication.loadLogin(document.body);
  170. });
  171. };
  172. };
  173. });
  174. (function(layout){
  175. layout.readys = [];
  176. layout.addReady = function(){
  177. for (var i = 0; i<arguments.length; i++){
  178. if (o2.typeOf(arguments[i])==="function") layout.readys.push(arguments[i]);
  179. }
  180. };
  181. var _requireApp = function(appNames, callback, clazzName){
  182. var appPath = appNames.split(".");
  183. var baseObject = o2.xApplication;
  184. appPath.each(function(path, i){
  185. if (i<(appPath.length-1)){
  186. baseObject[path] = baseObject[path] || {};
  187. }else {
  188. baseObject[path] = baseObject[path] || {"options": Object.clone(MWF.xApplication.Common.options)};
  189. }
  190. baseObject = baseObject[path];
  191. }.bind(this));
  192. if (!baseObject.options) baseObject.options = Object.clone(MWF.xApplication.Common.options);
  193. var _lpLoaded = false;
  194. MWF.xDesktop.requireApp(appNames, "lp."+o2.language, {
  195. "failure": function(){
  196. MWF.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
  197. }.bind(this)
  198. }, false);
  199. MWF.xDesktop.requireApp(appNames, clazzName, function(){
  200. if (callback) callback(baseObject);
  201. });
  202. };
  203. var _createNewApplication = function(e, appNamespace, appName, options, statusObj){
  204. var app = new appNamespace["Main"](this, options);
  205. app.desktop = layout;
  206. app.inBrowser = true;
  207. app.status = statusObj;
  208. app.load(true);
  209. var appId = appName;
  210. if (options.appId){
  211. appId = options.appId;
  212. }else{
  213. if (appNamespace.options.multitask) appId = appId+"-"+(new MWF.widget.UUID());
  214. }
  215. app.appId = appId;
  216. layout.app = app;
  217. layout.desktop.currentApp = app;
  218. var mask = document.getElementById("appContentMask");
  219. if (mask) mask.destroy();
  220. };
  221. var _openWorkAndroid = function(options){
  222. if (window.o2android && window.o2android.openO2Work) {
  223. if (options.workId) {
  224. window.o2android.openO2Work(options.workId, "", options.title || "");
  225. } else if (options.workCompletedId) {
  226. window.o2android.openO2Work("", options.workCompletedId, options.title || "");
  227. }
  228. return true;
  229. }
  230. return false;
  231. };
  232. var _openWorkIOS = function(options){
  233. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Work) {
  234. if (options.workId) {
  235. window.webkit.messageHandlers.openO2Work.postMessage({
  236. "work": options.workId,
  237. "workCompleted": "",
  238. "title": options.title || ""
  239. });
  240. } else if (options.workCompletedId) {
  241. window.webkit.messageHandlers.openO2Work.postMessage({
  242. "work": "",
  243. "workCompleted": options.workCompletedId,
  244. "title": options.title || ""
  245. });
  246. }
  247. return true;
  248. }
  249. return false;
  250. };
  251. var _openWorkHTML = function(options){
  252. var uri = new URI(window.location.href);
  253. var redirectlink = uri.getData("redirectlink");
  254. if (!redirectlink) {
  255. redirectlink = encodeURIComponent(locate.pathname + locate.search);
  256. } else {
  257. redirectlink = encodeURIComponent(redirectlink);
  258. }
  259. if (options.workId) {
  260. window.location = "workmobilewithaction.html?workid=" + options.workId + ((layout.debugger)? "&debugger":"") + "&redirectlink=" + redirectlink;
  261. } else if (options.workCompletedId) {
  262. window.location = "workmobilewithaction.html?workcompletedid=" + options.workCompletedId + ((layout.debugger)? "&debugger":"") + "&redirectlink=" + redirectlink;
  263. }
  264. };
  265. var _openWork = function(options){
  266. if (!_openWorkAndroid(options)) if (!_openWorkIOS(options)) _openWorkHTML(options);
  267. };
  268. var _openDocument = function(appNames, options, statusObj){
  269. var title = typeOf( options ) === "object" ? ( options.docTitle || options.title ) : "";
  270. title = title || "";
  271. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  272. if (window.o2android && window.o2android.openO2CmsDocument){
  273. window.o2android.openO2CmsDocument(options.documentId, title);
  274. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsDocument){
  275. window.webkit.messageHandlers.openO2CmsDocument.postMessage({"docId":options.documentId,"docTitle":title});
  276. }else{
  277. window.location = "appMobile.html?"+par + ((layout.debugger)? "&debugger":"");
  278. }
  279. };
  280. var _openCms = function(appNames, options, statusObj){
  281. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  282. if (window.o2android && window.o2android.openO2CmsApplication){
  283. window.o2android.openO2CmsApplication(options.columnId, options.title || "");
  284. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsApplication){
  285. window.webkit.messageHandlers.openO2CmsApplication.postMessage(options.columnId);
  286. }else{
  287. window.location = "appMobile.html?"+par + ((layout.debugger)? "&debugger":"");
  288. }
  289. };
  290. var _openMeeting = function(appNames, options, statusObj){
  291. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  292. if (window.o2android && window.o2android.openO2Meeting){
  293. window.o2android.openO2Meeting("");
  294. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Meeting){
  295. window.webkit.messageHandlers.openO2Meeting.postMessage("");
  296. }else{
  297. window.location = "appMobile.html?"+par + ((layout.debugger)? "&debugger":"");
  298. }
  299. };
  300. var _openCalendar = function(appNames, options, statusObj){
  301. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  302. if (window.o2android && window.o2android.openO2Calendar){
  303. window.o2android.openO2Calendar("");
  304. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Calendar){
  305. window.webkit.messageHandlers.openO2Calendar.postMessage("");
  306. }else{
  307. window.location = "appMobile.html?"+par + ((layout.debugger)? "&debugger":"");
  308. }
  309. };
  310. var _openTaskCenter = function(appNames, options, statusObj){
  311. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  312. var tab = ((options && options.navi) ? options.navi : "task").toLowerCase();
  313. if (tab==="done") tab = "taskCompleted";
  314. if (tab==="readed") tab = "readCompleted";
  315. if (window.o2android && window.o2android.openO2WorkSpace){
  316. window.o2android.openO2WorkSpace(tab);
  317. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2WorkSpace){
  318. window.webkit.messageHandlers.openO2WorkSpace.postMessage(tab);
  319. }else{
  320. window.location = "appMobile.html?"+par + ((layout.debugger)? "&debugger":"");
  321. }
  322. };
  323. var _openApplicationMobile = function(appNames, options, statusObj){
  324. switch (appNames) {
  325. case "process.Work":
  326. _openWork(options);
  327. break;
  328. case "cms.Document":
  329. _openDocument(appNames, options, statusObj);
  330. break;
  331. case "cms.Module":
  332. _openCms(appNames, options, statusObj);
  333. break;
  334. case "Meeting":
  335. _openMeeting(appNames, options, statusObj);
  336. break;
  337. case "Calendar":
  338. _openCalendar(appNames, options, statusObj);
  339. break;
  340. case "process.TaskCenter":
  341. _openTaskCenter(appNames, options, statusObj);
  342. break;
  343. default:
  344. var uri = new URI(window.location.href);
  345. var optionsStr = uri.getData("option");
  346. var statusStr = uri.getData("status");
  347. window.location = "appMobile.html?app="+appNames+"&option="+(optionsStr || "")+"&status="+(statusStr || "") + ((layout.debugger)? "&debugger":"");
  348. }
  349. };
  350. layout.openApplication = function(e, appNames, options, statusObj){
  351. if (layout.app){
  352. if (layout.mobile){
  353. _openApplicationMobile(appNames, options, statusObj);
  354. }else{
  355. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  356. return window.open("app.html?"+par + ((layout.debugger)? "&debugger":""), "_blank");
  357. }
  358. }else{
  359. var appPath = appNames.split(".");
  360. var appName = appPath[appPath.length-1];
  361. _requireApp(appNames, function(appNamespace){
  362. _createNewApplication(e, appNamespace, appName, options, statusObj);
  363. }.bind(this));
  364. }
  365. };
  366. layout.refreshApp = function(app){
  367. var status = app.recordStatus();
  368. var uri = new URI(window.location.href);
  369. var appNames = uri.getData("app");
  370. var optionsStr = uri.getData("option");
  371. var statusStr = uri.getData("status");
  372. if (status) statusStr = JSON.encode(status);
  373. var port = uri.get("port");
  374. window.location = uri.get("scheme") + "://" + uri.get("host") + ((port) ? ":" + port + "/" : "") + uri.get("directory ") + "?app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent(statusStr) + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "") + ((layout.debugger)? "&debugger":"");
  375. };
  376. layout.load =function(appNames, options, statusObj){
  377. layout.message = new MWF.xDesktop.MessageMobile();
  378. layout.message.load();
  379. layout.apps = [];
  380. layout.node = $("layout");
  381. var appName=appNames, m_status=statusObj, option=options;
  382. var topWindow = window.opener;
  383. if (topWindow){
  384. try{
  385. if (!appName) appName = topWindow.layout.desktop.openBrowserApp;
  386. if (!m_status) m_status = topWindow.layout.desktop.openBrowserStatus;
  387. if (!option) option = topWindow.layout.desktop.openBrowserOption;
  388. }catch(e){}
  389. }
  390. layout.openApplication(null, appName, option||{}, m_status);
  391. }
  392. })(layout);