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. var app = new appNamespace["Main"](this, options);
  173. app.desktop = layout;
  174. app.inBrowser = true;
  175. app.status = statusObj;
  176. app.load(true);
  177. var appId = appName;
  178. if (options.appId) {
  179. appId = options.appId;
  180. } else {
  181. if (appNamespace.options.multitask) appId = appId + "-" + (new o2.widget.UUID());
  182. }
  183. app.appId = appId;
  184. layout.app = app;
  185. layout.desktop.currentApp = app;
  186. var mask = document.getElementById("appContentMask");
  187. if (mask) mask.destroy();
  188. };
  189. var _openWorkAndroid = function (options) {
  190. if (window.o2android && window.o2android.openO2Work) {
  191. if (options.workId) {
  192. window.o2android.openO2Work(options.workId, "", options.title || "");
  193. } else if (options.workCompletedId) {
  194. window.o2android.openO2Work("", options.workCompletedId, options.title || "");
  195. }
  196. return true;
  197. }
  198. return false;
  199. };
  200. var _openWorkIOS = function (options) {
  201. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Work) {
  202. if (options.workId) {
  203. window.webkit.messageHandlers.openO2Work.postMessage({
  204. "work": options.workId,
  205. "workCompleted": "",
  206. "title": options.title || ""
  207. });
  208. } else if (options.workCompletedId) {
  209. window.webkit.messageHandlers.openO2Work.postMessage({
  210. "work": "",
  211. "workCompleted": options.workCompletedId,
  212. "title": options.title || ""
  213. });
  214. }
  215. return true;
  216. }
  217. return false;
  218. };
  219. var _openWorkHTML = function (options) {
  220. var uri = new URI(window.location.href);
  221. var redirectlink = uri.getData("redirectlink");
  222. if (!redirectlink) {
  223. redirectlink = encodeURIComponent(locate.pathname + locate.search);
  224. } else {
  225. redirectlink = encodeURIComponent(redirectlink);
  226. }
  227. if (options.workId) {
  228. window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink);
  229. } else if (options.workCompletedId) {
  230. window.location = o2.filterUrl("../x_desktop/workmobilewithaction.html?workcompletedid=" + options.workCompletedId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink);
  231. }
  232. };
  233. var _openWork = function (options) {
  234. if (!_openWorkAndroid(options)) if (!_openWorkIOS(options)) _openWorkHTML(options);
  235. };
  236. var _openDocument = function (appNames, options, statusObj) {
  237. var title = typeOf(options) === "object" ? (options.docTitle || options.title) : "";
  238. title = title || "";
  239. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  240. if (window.o2android && window.o2android.openO2CmsDocument) {
  241. window.o2android.openO2CmsDocument(options.documentId, title);
  242. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsDocument) {
  243. window.webkit.messageHandlers.openO2CmsDocument.postMessage({ "docId": options.documentId, "docTitle": title });
  244. } else {
  245. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  246. }
  247. };
  248. var _openCms = function (appNames, options, statusObj) {
  249. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  250. if (window.o2android && window.o2android.openO2CmsApplication) {
  251. window.o2android.openO2CmsApplication(options.columnId, options.title || "");
  252. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsApplication) {
  253. window.webkit.messageHandlers.openO2CmsApplication.postMessage(options.columnId);
  254. } else {
  255. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  256. }
  257. };
  258. var _openMeeting = function (appNames, options, statusObj) {
  259. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  260. if (window.o2android && window.o2android.openO2Meeting) {
  261. window.o2android.openO2Meeting("");
  262. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Meeting) {
  263. window.webkit.messageHandlers.openO2Meeting.postMessage("");
  264. } else {
  265. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  266. }
  267. };
  268. var _openCalendar = function (appNames, options, statusObj) {
  269. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  270. if (window.o2android && window.o2android.openO2Calendar) {
  271. window.o2android.openO2Calendar("");
  272. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Calendar) {
  273. window.webkit.messageHandlers.openO2Calendar.postMessage("");
  274. } else {
  275. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  276. }
  277. };
  278. var _openTaskCenter = function (appNames, options, statusObj) {
  279. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  280. var tab = ((options && options.navi) ? options.navi : "task").toLowerCase();
  281. if (tab === "done") tab = "taskCompleted";
  282. if (tab === "readed") tab = "readCompleted";
  283. if (window.o2android && window.o2android.openO2WorkSpace) {
  284. window.o2android.openO2WorkSpace(tab);
  285. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2WorkSpace) {
  286. window.webkit.messageHandlers.openO2WorkSpace.postMessage(tab);
  287. } else {
  288. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  289. }
  290. };
  291. var _openApplicationMobile = function (appNames, options, statusObj) {
  292. switch (appNames) {
  293. case "process.Work":
  294. _openWork(options);
  295. break;
  296. case "cms.Document":
  297. _openDocument(appNames, options, statusObj);
  298. break;
  299. case "cms.Module":
  300. _openCms(appNames, options, statusObj);
  301. break;
  302. case "Meeting":
  303. _openMeeting(appNames, options, statusObj);
  304. break;
  305. case "Calendar":
  306. _openCalendar(appNames, options, statusObj);
  307. break;
  308. case "process.TaskCenter":
  309. _openTaskCenter(appNames, options, statusObj);
  310. break;
  311. default:
  312. var uri = new URI(window.location.href);
  313. var optionsStr = uri.getData("option");
  314. var statusStr = uri.getData("status");
  315. window.location = o2.filterUrl("../x_desktop/appMobile.html?app=" + appNames + "&option=" + (optionsStr || "") + "&status=" + (statusStr || "") + ((layout.debugger) ? "&debugger" : ""));
  316. }
  317. };
  318. layout.openApplication = function (e, appNames, options, statusObj) {
  319. if (layout.app) {
  320. if (layout.mobile) {
  321. _openApplicationMobile(appNames, options, statusObj);
  322. } else {
  323. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  324. if (layout.app.$openWithSelf) {
  325. return window.location = o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  326. } else {
  327. return window.open(o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : "")), par);
  328. }
  329. }
  330. } else {
  331. var appPath = appNames.split(".");
  332. var appName = appPath[appPath.length - 1];
  333. _requireApp(appNames, function (appNamespace) {
  334. _createNewApplication(e, appNamespace, appName, options, statusObj);
  335. }.bind(this));
  336. }
  337. };
  338. layout.refreshApp = function (app) {
  339. var status = app.recordStatus();
  340. var uri = new URI(window.location.href);
  341. var appNames = uri.getData("app");
  342. var optionsStr = uri.getData("option");
  343. var statusStr = uri.getData("status");
  344. if (status) statusStr = JSON.encode(status);
  345. var port = uri.get("port");
  346. 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" : "");
  347. };
  348. layout.load = function (appNames, options, statusObj) {
  349. // layout.message = new o2.xDesktop.MessageMobile();
  350. // layout.message.load();
  351. layout.apps = [];
  352. layout.node = $("layout");
  353. var appName = appNames, m_status = statusObj, option = options;
  354. var topWindow = window.opener;
  355. if (topWindow) {
  356. try {
  357. if (!appName) appName = topWindow.layout.desktop.openBrowserApp;
  358. if (!m_status) m_status = topWindow.layout.desktop.openBrowserStatus;
  359. if (!option) option = topWindow.layout.desktop.openBrowserOption;
  360. } catch (e) { }
  361. }
  362. layout.openApplication(null, appName, option || {}, m_status);
  363. }
  364. })(layout);