base.js 23 KB

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