base_simple_anonymous.js 17 KB

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