base_simple.js 20 KB

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