base_simple_anonymous.js 18 KB

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