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