base_simple_anonymous.js 19 KB

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