base.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. if (!window.layout || !layout.desktop || !layout.addReady) {
  2. layout = window.layout || {};
  3. layout.desktop = layout;
  4. layout.desktop.type = "app";
  5. layout.apps = [];
  6. var locate = window.location;
  7. layout.protocol = locate.protocol;
  8. layout.port = locate.port;
  9. layout.inBrowser = true;
  10. layout.session = layout.session || {};
  11. layout.debugger = (locate.href.toString().indexOf("debugger") !== -1);
  12. layout.anonymous = (locate.href.toString().indexOf("anonymous") !== -1);
  13. o2.xApplication = o2.xApplication || {};
  14. o2.xDesktop = o2.xDesktop || {};
  15. o2.xDesktop.requireApp = function (module, clazz, callback, async) {
  16. o2.requireApp(module, clazz, callback, async);
  17. };
  18. (function (layout) {
  19. layout.readys = [];
  20. layout.addReady = function () {
  21. for (var i = 0; i < arguments.length; i++) {
  22. if (o2.typeOf(arguments[i]) === "function") {
  23. if (layout.isReady) {
  24. arguments[i].apply(window);
  25. } else {
  26. layout.readys.push(arguments[i]);
  27. }
  28. }
  29. }
  30. };
  31. var _requireApp = function (appNames, callback, clazzName) {
  32. var appPath = appNames.split(".");
  33. var baseObject = o2.xApplication;
  34. appPath.each(function (path, i) {
  35. if (i < (appPath.length - 1)) {
  36. baseObject[path] = baseObject[path] || {};
  37. } else {
  38. baseObject[path] = baseObject[path] || {"options": Object.clone(o2.xApplication.Common.options)};
  39. }
  40. baseObject = baseObject[path];
  41. }.bind(this));
  42. if (!baseObject.options) baseObject.options = Object.clone(o2.xApplication.Common.options);
  43. var _lpLoaded = false;
  44. o2.xDesktop.requireApp(appNames, "lp." + o2.language, {
  45. "onFailure": function () {
  46. o2.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
  47. }.bind(this)
  48. }, false);
  49. o2.xDesktop.requireApp(appNames, clazzName, function () {
  50. if (callback) callback(baseObject);
  51. });
  52. };
  53. var _createNewApplication = function (e, appNamespace, appName, options, statusObj, inBrowser, taskitem, notCurrent, node) {
  54. if (options) {
  55. options.event = e;
  56. } else {
  57. options = {"event": e};
  58. }
  59. var app = new appNamespace["Main"](layout.desktop, options);
  60. app.desktop = layout.desktop;
  61. app.status = statusObj;
  62. app.inBrowser = !!(inBrowser || layout.inBrowser);
  63. app.windowNode = node;
  64. if (layout.desktop.type === "layout") {
  65. app.appId = (options.appId) ? options.appId : ((appNamespace.options.multitask) ? appName + "-" + (new o2.widget.UUID()) : appName);
  66. app.options.appId = app.appId;
  67. if (layout.desktop.createTaskItem) {
  68. if (!taskitem) taskitem = layout.desktop.createTaskItem(app);
  69. app.taskitem = taskitem;
  70. app.taskitem.app = app;
  71. }
  72. app.isLoadApplication = true;
  73. app.load(!notCurrent);
  74. if (!layout.desktop.apps) layout.desktop.apps = {};
  75. if (layout.desktop.apps[app.appId]) {
  76. var tmpApp = layout.desktop.apps[app.appId];
  77. } else {
  78. layout.desktop.apps[app.appId] = app;
  79. }
  80. layout.desktop.appArr.push(app);
  81. layout.desktop.appCurrentList.push(app);
  82. if (!notCurrent) layout.desktop.currentApp = app;
  83. } else {
  84. app.load(true);
  85. layout.app = app;
  86. }
  87. var mask = document.getElementById("appContentMask");
  88. if (mask) mask.destroy();
  89. };
  90. var _openWorkAndroid = function (options) {
  91. if (window.o2android && window.o2android.postMessage) {
  92. var body = {
  93. type: "openO2Work",
  94. data: {
  95. title : options.title || ""
  96. }
  97. };
  98. if (options.workId) {
  99. body.data.workId = options.workId;
  100. } else if (options.workCompletedId) {
  101. body.data.workCompletedId = options.workCompletedId;
  102. } else if (options.draftId) {
  103. body.data.draftId = options.draftId;
  104. }
  105. window.o2android.postMessage(JSON.stringify(body));
  106. return true;
  107. }
  108. if (window.o2android && window.o2android.openO2Work) {
  109. if (options.workId) {
  110. window.o2android.openO2Work(options.workId, "", options.title || options.docTitle || "");
  111. } else if (options.workCompletedId) {
  112. window.o2android.openO2Work("", options.workCompletedId, options.title || options.docTitle || "");
  113. }
  114. return true;
  115. }
  116. return false;
  117. };
  118. var _openWorkIOS = function (options) {
  119. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Work) {
  120. if (options.workId) {
  121. window.webkit.messageHandlers.openO2Work.postMessage({
  122. "work": options.workId,
  123. "workCompleted": "",
  124. "draftId": options.draftId,
  125. "title": options.title || options.docTitle || ""
  126. });
  127. } else if (options.workCompletedId) {
  128. window.webkit.messageHandlers.openO2Work.postMessage({
  129. "work": "",
  130. "workCompleted": options.workCompletedId,
  131. "draftId": options.draftId,
  132. "title": options.title || options.docTitle || ""
  133. });
  134. }
  135. return true;
  136. }
  137. return false;
  138. };
  139. var _openWorkHTML = function (options) {
  140. var uri = new URI(window.location.href);
  141. var redirectlink = uri.getData("redirectlink");
  142. if (!redirectlink) {
  143. redirectlink = encodeURIComponent(locate.pathname + locate.search);
  144. } else {
  145. redirectlink = encodeURIComponent(redirectlink);
  146. }
  147. var docurl = "../x_desktop/workmobilewithaction.html".toURI();
  148. if (options.draft) {
  149. var par = "draft=" + encodeURIComponent(JSON.stringify(options.draft));
  150. docurl = "../x_desktop/workmobilewithaction.html?" + par;
  151. } else {
  152. docurl = docurl.setData(options).toString();
  153. }
  154. var job = (options.jobid || options.jobId || options.job);
  155. if (job) docurl += ((docurl.indexOf("?") != -1) ? "&" : "?") + "jobid=" + job;
  156. docurl += ((redirectlink) ? "&redirectlink=" + redirectlink : "");
  157. docurl += ((layout.debugger) ? "&debugger" : "");
  158. //使用相对路径不需要filterUrl
  159. //window.location = o2.filterUrl(docurl);
  160. window.location = docurl;
  161. };
  162. var _openWork = function (options) {
  163. if (!_openWorkAndroid(options)) if (!_openWorkIOS(options)) _openWorkHTML(options);
  164. };
  165. var _openDocument = function (appNames, options, statusObj) {
  166. var title = typeOf(options) === "object" ? (options.docTitle || options.title) : "";
  167. title = title || "";
  168. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  169. if (window.o2android && window.o2android.postMessage) {
  170. var body = {
  171. type: "openO2CmsDocument",
  172. data: {
  173. docId : options.documentId,
  174. title: title,
  175. options: options
  176. }
  177. };
  178. window.o2android.postMessage(JSON.stringify(body));
  179. } else if (window.o2android && window.o2android.openO2CmsDocumentV2) {
  180. window.o2android.openO2CmsDocumentV2(options.documentId, title, JSON.stringify(options));
  181. } else if (window.o2android && window.o2android.openO2CmsDocument) {
  182. window.o2android.openO2CmsDocument(options.documentId, title);
  183. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsDocument) {
  184. window.webkit.messageHandlers.openO2CmsDocument.postMessage({
  185. "docId": options.documentId,
  186. "docTitle": title, "options": JSON.stringify(options)
  187. });
  188. } else {
  189. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  190. }
  191. };
  192. var _openCms = 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: "openO2CmsApplication",
  197. data: {
  198. appId : options.columnId,
  199. title: options.title || "",
  200. categoryId: options.categoryId || ""
  201. }
  202. };
  203. window.o2android.postMessage(JSON.stringify(body));
  204. } else if (window.o2android && window.o2android.openO2CmsApplication) {
  205. window.o2android.openO2CmsApplication(options.columnId, options.title || "");
  206. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsApplication) {
  207. window.webkit.messageHandlers.openO2CmsApplication.postMessage(options.columnId);
  208. } else {
  209. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  210. }
  211. };
  212. var _openMeeting = function (appNames, options, statusObj) {
  213. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  214. if (window.o2android && window.o2android.postMessage) {
  215. var body = {
  216. type: "openO2Meeting",
  217. data: {}
  218. };
  219. window.o2android.postMessage(JSON.stringify(body));
  220. } else if (window.o2android && window.o2android.openO2Meeting) {
  221. window.o2android.openO2Meeting("");
  222. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Meeting) {
  223. window.webkit.messageHandlers.openO2Meeting.postMessage("");
  224. } else {
  225. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  226. }
  227. };
  228. var _openCalendar = function (appNames, options, statusObj) {
  229. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  230. if (window.o2android && window.o2android.postMessage) {
  231. var body = {
  232. type: "openO2Calendar",
  233. data: {}
  234. };
  235. window.o2android.postMessage(JSON.stringify(body));
  236. } else if (window.o2android && window.o2android.openO2Calendar) {
  237. window.o2android.openO2Calendar("");
  238. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Calendar) {
  239. window.webkit.messageHandlers.openO2Calendar.postMessage("");
  240. } else {
  241. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  242. }
  243. };
  244. var _openTaskCenter = function (appNames, options, statusObj) {
  245. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  246. var tab = ((options && options.navi) ? options.navi : "task").toLowerCase();
  247. if (tab === "done") tab = "taskCompleted";
  248. if (tab === "readed") tab = "readCompleted";
  249. if (window.o2android && window.o2android.postMessage) {
  250. var body = {
  251. type: "openO2WorkSpace",
  252. data: { type: tab }
  253. };
  254. window.o2android.postMessage(JSON.stringify(body));
  255. } else if (window.o2android && window.o2android.openO2WorkSpace) {
  256. window.o2android.openO2WorkSpace(tab);
  257. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2WorkSpace) {
  258. window.webkit.messageHandlers.openO2WorkSpace.postMessage(tab);
  259. } else {
  260. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  261. }
  262. };
  263. var _openApplicationMobile = function (appNames, options, statusObj) {
  264. switch (appNames) {
  265. case "process.Work":
  266. _openWork(options);
  267. break;
  268. case "cms.Document":
  269. _openDocument(appNames, options, statusObj);
  270. break;
  271. case "cms.Module":
  272. _openCms(appNames, options, statusObj);
  273. break;
  274. case "Meeting":
  275. _openMeeting(appNames, options, statusObj);
  276. break;
  277. case "Calendar":
  278. _openCalendar(appNames, options, statusObj);
  279. break;
  280. case "process.TaskCenter":
  281. _openTaskCenter(appNames, options, statusObj);
  282. break;
  283. default:
  284. var optionsStr, statusStr;
  285. if( options || statusObj){
  286. optionsStr = encodeURIComponent((options) ? JSON.encode(options) : "")
  287. statusStr = encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "")
  288. }else{
  289. var uri = new URI(window.location.href);
  290. optionsStr = uri.getData("option");
  291. statusStr = uri.getData("status");
  292. }
  293. window.location = o2.filterUrl("../x_desktop/appMobile.html?app=" + appNames + "&option=" + (optionsStr || "") + "&status=" + (statusStr || "") + ((layout.debugger) ? "&debugger" : ""));
  294. }
  295. };
  296. var _openWindow = function (url, par) {
  297. var a = new Element("a", {
  298. "href": url,
  299. "target": par
  300. });
  301. a.click();
  302. a.destroy();
  303. };
  304. var _openApplicationPC = function (appNames, options, statusObj) {
  305. if (options) delete options.docTitle;
  306. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  307. switch (appNames) {
  308. case "process.Work":
  309. var url = "../x_desktop/work.html";
  310. if (options.draft) {
  311. url = "../x_desktop/app.html?" + par;
  312. } else {
  313. Object.keys(options).forEach(function (k) {
  314. if (options[k]) url += ((url.indexOf("?") != -1) ? "&" : "?") + k + "=" + options[k];
  315. });
  316. //url = url.setData(options).toString();
  317. }
  318. var job = (options.jobid || options.jobId || options.job);
  319. if (job) url += ((url.indexOf("?") != -1) ? "&" : "?") + "jobid=" + job;
  320. url += ((layout.debugger) ? "&debugger" : "");
  321. if (layout.app.$openWithSelf) {
  322. return window.location = o2.filterUrl(url);
  323. } else {
  324. return window.open(o2.filterUrl(url), par);
  325. }
  326. break;
  327. case "cms.Document":
  328. // _openDocument(appNames, options, statusObj);
  329. var url = "../x_desktop/cmsdoc.html".toURI();
  330. url = url.setData(options).toString();
  331. url += ((layout.debugger) ? "&debugger" : "");
  332. if (layout.app.$openWithSelf) {
  333. return window.location = o2.filterUrl(url);
  334. } else {
  335. return window.open(o2.filterUrl(url), par);
  336. }
  337. break;
  338. // case "cms.Module":
  339. // _openCms(appNames, options, statusObj);
  340. // break;
  341. // case "Meeting":
  342. // _openMeeting(appNames, options, statusObj);
  343. // break;
  344. // case "Calendar":
  345. // _openCalendar(appNames, options, statusObj);
  346. // break;
  347. // case "process.TaskCenter":
  348. // _openTaskCenter(appNames, options, statusObj);
  349. // break;
  350. default:
  351. if (layout.app.$openWithSelf) {
  352. return window.location = o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  353. } else {
  354. return window.open(o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : "")), par);
  355. }
  356. }
  357. };
  358. layout.openApplication = function (e, appNames, options, statusObj, inBrowser, taskitem, notCurrent, node) {
  359. if (appNames.substring(0, 4) === "@url") {
  360. var url = appNames.replace(/\@url\:/i, "");
  361. var a = new Element("a", {"href": url, "target": "_blank"});
  362. a.click();
  363. a.destroy();
  364. a = null;
  365. return true;
  366. }
  367. if (layout.app) {
  368. if (layout.mobile) {
  369. _openApplicationMobile(appNames, options, statusObj);
  370. } else {
  371. return _openApplicationPC(appNames, options, statusObj);
  372. }
  373. } else {
  374. var appPath = appNames.split(".");
  375. var appName = appPath[appPath.length - 1];
  376. _requireApp(appNames, function (appNamespace) {
  377. var appId = (options && options.appId) ? options.appId : ((appNamespace.options.multitask) ? "" : appName);
  378. if (appId && layout.desktop.apps && layout.desktop.apps[appId]) {
  379. layout.desktop.apps[appId].setCurrent();
  380. } else {
  381. if (options) options.appId = appId;
  382. if (appNamespace.loading && appNamespace.loading.then){
  383. if (!layout.desktop.loadingAppIdArr) layout.desktop.loadingAppIdArr = [];
  384. if( !layout.desktop.loadingAppIdArr.contains( appId ) ){
  385. if( appId )layout.desktop.loadingAppIdArr.push(appId);
  386. appNamespace.loading.then(function(){
  387. _createNewApplication(e, appNamespace, appName, (options || {"appId": appId}), statusObj, inBrowser, taskitem, notCurrent, node);
  388. if( appId )layout.desktop.loadingAppIdArr.erase(appId);
  389. });
  390. }
  391. }else{
  392. _createNewApplication(e, appNamespace, appName, (options || {"appId": appId}), statusObj, inBrowser, taskitem, notCurrent, node);
  393. }
  394. }
  395. }.bind(this));
  396. }
  397. };
  398. layout.refreshApp = function (app) {
  399. var status = app.recordStatus();
  400. var _uri = new URI(window.location.href);
  401. var appNames = _uri.getData("app");
  402. var optionsStr = _uri.getData("option");
  403. var statusStr = _uri.getData("status");
  404. if (status) statusStr = JSON.encode(status);
  405. var port = _uri.get("port");
  406. var u = _uri.get("scheme") + "://" + _uri.get("host") + ((port && port != "80") ? ":" + port : "") + _uri.get("directory") + _uri.get("file") + "?app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent(statusStr) + "&option=" + encodeURIComponent((optionsStr) ? JSON.encode(optionsStr) : "") + ((layout.debugger) ? "&debugger" : "");
  407. u = o2.filterUrl(u);
  408. window.location = u;
  409. };
  410. layout.load = function (appNames, options, statusObj) {
  411. layout.apps = [];
  412. layout.node = $("layout") || $("appContent") || document.body;
  413. var appName = appNames, m_status = statusObj, option = options;
  414. var topWindow = window.opener;
  415. if (topWindow) {
  416. try {
  417. if (!appName) appName = topWindow.layout.desktop.openBrowserApp;
  418. if (!m_status) m_status = topWindow.layout.desktop.openBrowserStatus;
  419. if (!option) option = topWindow.layout.desktop.openBrowserOption;
  420. } catch (e) {
  421. }
  422. }
  423. layout.openApplication(null, appName, option || {}, m_status);
  424. };
  425. layout.getFormDesignerStyle = function (callback) {
  426. if (!this.formDesignerStyle) {
  427. this.formDesignerStyle = "default";
  428. MWF.UD.getData("formDesignerStyle", function (json) {
  429. if (json.data) {
  430. var styles = JSON.decode(json.data);
  431. this.formDesignerStyle = styles.style;
  432. }
  433. if (callback) callback();
  434. }.bind(this));
  435. } else {
  436. if (callback) callback();
  437. }
  438. }
  439. })(layout);
  440. }