base_simple.js 21 KB

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