base_simple.js 20 KB

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