base_simple_anonymous.js 17 KB

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