base_simple.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. data: {
  154. name: "anonymous",
  155. roleList: []
  156. }
  157. });
  158. } else {
  159. //用户未经登录
  160. //打开登录页面
  161. // var _loadResource = function (callback) {
  162. // var isLoadedA = true;
  163. // var isLoadedB = false;
  164. // //var isLoadedC = false;
  165. //
  166. // //var lp = o2.session.path+"/lp/"+o2.language+".js";
  167. // var modules = [
  168. // // "o2.xDesktop.Dialog",
  169. // "o2.xDesktop.UserData",
  170. // // "o2.xDesktop.Access",
  171. // // "o2.widget.UUID",
  172. // // "o2.xDesktop.Menu",
  173. // // //"o2.xDesktop.shortcut",
  174. // // "o2.widget.PinYin",
  175. // // "o2.xDesktop.Access",
  176. // //"o2.xDesktop.MessageMobile"
  177. // ];
  178. // //o2.xDesktop.requireApp("Common", "", null, false);
  179. // var _check = function () { if (isLoadedA && isLoadedB) if (callback) callback(); };
  180. //
  181. // //o2.load(["../o2_lib/mootools/plugin/mBox.min.js"], function () { _loadProgressBar(); isLoadedA = true; _check(); });
  182. // o2.require("o2.widget.Common", function () {
  183. // _loadProgressBar();
  184. // o2.require(modules, {
  185. // "onSuccess": function () {
  186. // o2.requireApp("Common", "", function () { isLoadedB = true; _check(); })
  187. // },
  188. // "onEvery": function () {
  189. // _loadProgressBar();
  190. // }
  191. // });
  192. // });
  193. // };
  194. //_loadResource(function () {
  195. _loadProgressBar(true);
  196. layout.openLogin();
  197. //});
  198. }
  199. });
  200. layout.openLogin = function () {
  201. //o2.require("o2.widget.Common", null, false);
  202. //o2.require("o2.xDesktop.Authentication", function () {
  203. layout.authentication = new o2.xDesktop.Authentication({
  204. "style": "flat",
  205. "onLogin": _load.bind(layout)
  206. });
  207. layout.authentication.loadLogin(document.body);
  208. var loadingNode = $("browser_loading");
  209. if (loadingNode) loadingNode.fade("out");
  210. //});
  211. };
  212. };
  213. });
  214. (function (layout) {
  215. layout.readys = [];
  216. layout.addReady = function () {
  217. for (var i = 0; i < arguments.length; i++) {
  218. if (o2.typeOf(arguments[i]) === "function") layout.readys.push(arguments[i]);
  219. }
  220. };
  221. var _requireApp = function (appNames, callback, clazzName) {
  222. var appPath = appNames.split(".");
  223. var baseObject = o2.xApplication;
  224. appPath.each(function (path, i) {
  225. if (i < (appPath.length - 1)) {
  226. baseObject[path] = baseObject[path] || {};
  227. } else {
  228. baseObject[path] = baseObject[path] || { "options": Object.clone(o2.xApplication.Common.options) };
  229. }
  230. baseObject = baseObject[path];
  231. }.bind(this));
  232. if (!baseObject.options) baseObject.options = Object.clone(o2.xApplication.Common.options);
  233. var _lpLoaded = false;
  234. o2.xDesktop.requireApp(appNames, "lp." + o2.language, {
  235. "failure": function () {
  236. o2.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
  237. }.bind(this)
  238. }, false);
  239. o2.xDesktop.requireApp(appNames, clazzName, function () {
  240. if (callback) callback(baseObject);
  241. });
  242. };
  243. var _createNewApplication = function (e, appNamespace, appName, options, statusObj) {
  244. var app = new appNamespace["Main"](this, options);
  245. app.desktop = layout;
  246. app.inBrowser = true;
  247. app.status = statusObj;
  248. app.load(true);
  249. var appId = appName;
  250. if (options.appId) {
  251. appId = options.appId;
  252. } else {
  253. if (appNamespace.options.multitask) appId = appId + "-" + (new o2.widget.UUID());
  254. }
  255. app.appId = appId;
  256. layout.app = app;
  257. layout.desktop.currentApp = app;
  258. var mask = document.getElementById("appContentMask");
  259. if (mask) mask.destroy();
  260. };
  261. var _openWorkAndroid = function (options) {
  262. if (window.o2android && window.o2android.openO2Work) {
  263. if (options.workId) {
  264. window.o2android.openO2Work(options.workId, "", options.title || "");
  265. } else if (options.workCompletedId) {
  266. window.o2android.openO2Work("", options.workCompletedId, options.title || "");
  267. }
  268. return true;
  269. }
  270. return false;
  271. };
  272. var _openWorkIOS = function (options) {
  273. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Work) {
  274. if (options.workId) {
  275. window.webkit.messageHandlers.openO2Work.postMessage({
  276. "work": options.workId,
  277. "workCompleted": "",
  278. "title": options.title || ""
  279. });
  280. } else if (options.workCompletedId) {
  281. window.webkit.messageHandlers.openO2Work.postMessage({
  282. "work": "",
  283. "workCompleted": options.workCompletedId,
  284. "title": options.title || ""
  285. });
  286. }
  287. return true;
  288. }
  289. return false;
  290. };
  291. var _openWorkHTML = function (options) {
  292. var uri = new URI(window.location.href);
  293. var redirectlink = uri.getData("redirectlink");
  294. if (!redirectlink) {
  295. redirectlink = encodeURIComponent(locate.pathname + locate.search);
  296. } else {
  297. redirectlink = encodeURIComponent(redirectlink);
  298. }
  299. if (options.workId) {
  300. window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink);
  301. } else if (options.workCompletedId) {
  302. window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?workcompletedid=" + options.workCompletedId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink);
  303. }else if (options.draft){
  304. window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?draft=" + JSON.stringify(options.draft) + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink);
  305. }else {
  306. console.log("open work 错误,缺少参数!");
  307. }
  308. };
  309. var _openWork = function (options) {
  310. if (!_openWorkAndroid(options)) if (!_openWorkIOS(options)) _openWorkHTML(options);
  311. };
  312. var _openDocument = function (appNames, options, statusObj) {
  313. var title = typeOf(options) === "object" ? (options.docTitle || options.title) : "";
  314. title = title || "";
  315. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  316. if (window.o2android && window.o2android.openO2CmsDocument) {
  317. window.o2android.openO2CmsDocument(options.documentId, title);
  318. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsDocument) {
  319. window.webkit.messageHandlers.openO2CmsDocument.postMessage({ "docId": options.documentId, "docTitle": title });
  320. } else {
  321. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  322. }
  323. };
  324. var _openCms = function (appNames, options, statusObj) {
  325. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  326. if (window.o2android && window.o2android.openO2CmsApplication) {
  327. window.o2android.openO2CmsApplication(options.columnId, options.title || "");
  328. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsApplication) {
  329. window.webkit.messageHandlers.openO2CmsApplication.postMessage(options.columnId);
  330. } else {
  331. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  332. }
  333. };
  334. var _openMeeting = function (appNames, options, statusObj) {
  335. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  336. if (window.o2android && window.o2android.openO2Meeting) {
  337. window.o2android.openO2Meeting("");
  338. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Meeting) {
  339. window.webkit.messageHandlers.openO2Meeting.postMessage("");
  340. } else {
  341. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  342. }
  343. };
  344. var _openCalendar = function (appNames, options, statusObj) {
  345. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  346. if (window.o2android && window.o2android.openO2Calendar) {
  347. window.o2android.openO2Calendar("");
  348. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Calendar) {
  349. window.webkit.messageHandlers.openO2Calendar.postMessage("");
  350. } else {
  351. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  352. }
  353. };
  354. var _openTaskCenter = function (appNames, options, statusObj) {
  355. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  356. var tab = ((options && options.navi) ? options.navi : "task").toLowerCase();
  357. if (tab === "done") tab = "taskCompleted";
  358. if (tab === "readed") tab = "readCompleted";
  359. if (window.o2android && window.o2android.openO2WorkSpace) {
  360. window.o2android.openO2WorkSpace(tab);
  361. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2WorkSpace) {
  362. window.webkit.messageHandlers.openO2WorkSpace.postMessage(tab);
  363. } else {
  364. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  365. }
  366. };
  367. var _openApplicationMobile = function (appNames, options, statusObj) {
  368. switch (appNames) {
  369. case "process.Work":
  370. _openWork(options);
  371. break;
  372. case "cms.Document":
  373. _openDocument(appNames, options, statusObj);
  374. break;
  375. case "cms.Module":
  376. _openCms(appNames, options, statusObj);
  377. break;
  378. case "Meeting":
  379. _openMeeting(appNames, options, statusObj);
  380. break;
  381. case "Calendar":
  382. _openCalendar(appNames, options, statusObj);
  383. break;
  384. case "process.TaskCenter":
  385. _openTaskCenter(appNames, options, statusObj);
  386. break;
  387. default:
  388. var uri = new URI(window.location.href);
  389. var optionsStr = uri.getData("option");
  390. var statusStr = uri.getData("status");
  391. window.location = o2.filterUrl("../x_desktop/appMobile.html?app=" + appNames + "&option=" + (optionsStr || "") + "&status=" + (statusStr || "") + ((layout.debugger) ? "&debugger" : ""));
  392. }
  393. };
  394. layout.openApplication = function (e, appNames, options, statusObj) {
  395. if (layout.app) {
  396. if (layout.mobile) {
  397. _openApplicationMobile(appNames, options, statusObj);
  398. } else {
  399. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  400. if (layout.app.$openWithSelf) {
  401. return window.location = o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  402. } else {
  403. return window.open(o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : "")), par);
  404. }
  405. }
  406. } else {
  407. var appPath = appNames.split(".");
  408. var appName = appPath[appPath.length - 1];
  409. _requireApp(appNames, function (appNamespace) {
  410. _createNewApplication(e, appNamespace, appName, options, statusObj);
  411. }.bind(this));
  412. }
  413. };
  414. layout.refreshApp = function (app) {
  415. var status = app.recordStatus();
  416. var uri = new URI(window.location.href);
  417. var appNames = uri.getData("app");
  418. var optionsStr = uri.getData("option");
  419. var statusStr = uri.getData("status");
  420. if (status) statusStr = JSON.encode(status);
  421. var port = uri.get("port");
  422. 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" : "");
  423. };
  424. layout.load = function (appNames, options, statusObj) {
  425. // layout.message = new o2.xDesktop.MessageMobile();
  426. // layout.message.load();
  427. layout.apps = [];
  428. layout.node = $("layout");
  429. var appName = appNames, m_status = statusObj, option = options;
  430. var topWindow = window.opener;
  431. if (topWindow) {
  432. try {
  433. if (!appName) appName = topWindow.layout.desktop.openBrowserApp;
  434. if (!m_status) m_status = topWindow.layout.desktop.openBrowserStatus;
  435. if (!option) option = topWindow.layout.desktop.openBrowserOption;
  436. } catch (e) { }
  437. }
  438. layout.openApplication(null, appName, option || {}, m_status);
  439. }
  440. })(layout);