base_simple.js 24 KB

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