xbase.js 20 KB

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