base_simple_anonymous.js 22 KB

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