xbase.js 24 KB

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