base_simple.js 20 KB

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