base.js 19 KB

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