base.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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"){
  20. if (layout.isReady){
  21. arguments[i].apply(window);
  22. }else{
  23. layout.readys.push(arguments[i]);
  24. }
  25. }
  26. }
  27. };
  28. var _requireApp = function (appNames, callback, clazzName) {
  29. var appPath = appNames.split(".");
  30. var baseObject = o2.xApplication;
  31. appPath.each(function (path, i) {
  32. if (i < (appPath.length - 1)) {
  33. baseObject[path] = baseObject[path] || {};
  34. } else {
  35. baseObject[path] = baseObject[path] || { "options": Object.clone(o2.xApplication.Common.options) };
  36. }
  37. baseObject = baseObject[path];
  38. }.bind(this));
  39. if (!baseObject.options) baseObject.options = Object.clone(o2.xApplication.Common.options);
  40. var _lpLoaded = false;
  41. o2.xDesktop.requireApp(appNames, "lp." + o2.language, {
  42. "onFailure": function () {
  43. o2.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
  44. }.bind(this)
  45. }, false);
  46. o2.xDesktop.requireApp(appNames, clazzName, function () {
  47. if (callback) callback(baseObject);
  48. });
  49. };
  50. var _createNewApplication = function (e, appNamespace, appName, options, statusObj, inBrowser, taskitem, notCurrent) {
  51. if (options) { options.event = e; } else { options = { "event": e }; }
  52. var app = new appNamespace["Main"](layout.desktop, options);
  53. app.desktop = layout.desktop;
  54. app.status = statusObj;
  55. app.inBrowser = !!(inBrowser || layout.inBrowser);
  56. if (layout.desktop.type === "layout") {
  57. app.appId = (options.appId) ? options.appId : ((appNamespace.options.multitask) ? appName + "-" + (new o2.widget.UUID()) : appName);
  58. app.options.appId = app.appId;
  59. if (layout.desktop.createTaskItem){
  60. if (!taskitem) taskitem = layout.desktop.createTaskItem(app);
  61. app.taskitem = taskitem;
  62. app.taskitem.app = app;
  63. }
  64. app.isLoadApplication = true;
  65. app.load(!notCurrent);
  66. if (!layout.desktop.apps) layout.desktop.apps = {};
  67. if (layout.desktop.apps[app.appId]) {
  68. var tmpApp = layout.desktop.apps[app.appId];
  69. } else {
  70. layout.desktop.apps[app.appId] = app;
  71. }
  72. layout.desktop.appArr.push(app);
  73. layout.desktop.appCurrentList.push(app);
  74. if (!notCurrent) layout.desktop.currentApp = app;
  75. } else {
  76. app.load(true);
  77. layout.app = app;
  78. }
  79. var mask = document.getElementById("appContentMask");
  80. if (mask) mask.destroy();
  81. };
  82. var _openWorkAndroid = function (options) {
  83. if (window.o2android && window.o2android.openO2Work) {
  84. if (options.workId) {
  85. window.o2android.openO2Work(options.workId, "", options.title || options.docTitle || "");
  86. } else if (options.workCompletedId) {
  87. window.o2android.openO2Work("", options.workCompletedId, options.title || options.docTitle || "");
  88. }
  89. return true;
  90. }
  91. return false;
  92. };
  93. var _openWorkIOS = function (options) {
  94. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Work) {
  95. if (options.workId) {
  96. window.webkit.messageHandlers.openO2Work.postMessage({
  97. "work": options.workId,
  98. "workCompleted": "",
  99. "title": options.title || options.docTitle || ""
  100. });
  101. } else if (options.workCompletedId) {
  102. window.webkit.messageHandlers.openO2Work.postMessage({
  103. "work": "",
  104. "workCompleted": options.workCompletedId,
  105. "title": options.title || options.docTitle || ""
  106. });
  107. }
  108. return true;
  109. }
  110. return false;
  111. };
  112. var _openWorkHTML = function (options) {
  113. var uri = new URI(window.location.href);
  114. var redirectlink = uri.getData("redirectlink");
  115. if (!redirectlink) {
  116. redirectlink = encodeURIComponent(locate.pathname + locate.search);
  117. } else {
  118. redirectlink = encodeURIComponent(redirectlink);
  119. }
  120. var docurl = "../x_desktop/workmobilewithaction.html".toURI();
  121. if (options.draft){
  122. var par = "draft="+encodeURIComponent(JSON.stringify(options.draft));
  123. docurl = "../x_desktop/workmobilewithaction.html?" + par;
  124. }else{
  125. docurl = docurl.setData(options).toString();
  126. }
  127. var job = (options.jobid || options.jobId || options.job);
  128. if (job) docurl += ((docurl.indexOf("?")!=-1) ? "&" : "?") + "jobid="+job;
  129. docurl += ((redirectlink) ? "&redirectlink=" + redirectlink : "");
  130. docurl +=((layout.debugger) ? "&debugger" : "");
  131. window.location = o2.filterUrl(docurl);
  132. };
  133. var _openWork = function (options) {
  134. if (!_openWorkAndroid(options)) if (!_openWorkIOS(options)) _openWorkHTML(options);
  135. };
  136. var _openDocument = function (appNames, options, statusObj) {
  137. var title = typeOf(options) === "object" ? (options.docTitle || options.title) : "";
  138. title = title || "";
  139. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  140. if (window.o2android && window.o2android.openO2CmsDocument) {
  141. window.o2android.openO2CmsDocument(options.documentId, title);
  142. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsDocument) {
  143. window.webkit.messageHandlers.openO2CmsDocument.postMessage({ "docId": options.documentId, "docTitle": title });
  144. } else {
  145. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  146. }
  147. };
  148. var _openCms = function (appNames, options, statusObj) {
  149. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  150. if (window.o2android && window.o2android.openO2CmsApplication) {
  151. window.o2android.openO2CmsApplication(options.columnId, options.title || "");
  152. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsApplication) {
  153. window.webkit.messageHandlers.openO2CmsApplication.postMessage(options.columnId);
  154. } else {
  155. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  156. }
  157. };
  158. var _openMeeting = function (appNames, options, statusObj) {
  159. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  160. if (window.o2android && window.o2android.openO2Meeting) {
  161. window.o2android.openO2Meeting("");
  162. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Meeting) {
  163. window.webkit.messageHandlers.openO2Meeting.postMessage("");
  164. } else {
  165. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  166. }
  167. };
  168. var _openCalendar = function (appNames, options, statusObj) {
  169. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  170. if (window.o2android && window.o2android.openO2Calendar) {
  171. window.o2android.openO2Calendar("");
  172. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Calendar) {
  173. window.webkit.messageHandlers.openO2Calendar.postMessage("");
  174. } else {
  175. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  176. }
  177. };
  178. var _openTaskCenter = function (appNames, options, statusObj) {
  179. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  180. var tab = ((options && options.navi) ? options.navi : "task").toLowerCase();
  181. if (tab === "done") tab = "taskCompleted";
  182. if (tab === "readed") tab = "readCompleted";
  183. if (window.o2android && window.o2android.openO2WorkSpace) {
  184. window.o2android.openO2WorkSpace(tab);
  185. } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2WorkSpace) {
  186. window.webkit.messageHandlers.openO2WorkSpace.postMessage(tab);
  187. } else {
  188. window.location = o2.filterUrl("../x_desktop/appMobile.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  189. }
  190. };
  191. var _openApplicationMobile = function (appNames, options, statusObj) {
  192. switch (appNames) {
  193. case "process.Work":
  194. _openWork(options);
  195. break;
  196. case "cms.Document":
  197. _openDocument(appNames, options, statusObj);
  198. break;
  199. case "cms.Module":
  200. _openCms(appNames, options, statusObj);
  201. break;
  202. case "Meeting":
  203. _openMeeting(appNames, options, statusObj);
  204. break;
  205. case "Calendar":
  206. _openCalendar(appNames, options, statusObj);
  207. break;
  208. case "process.TaskCenter":
  209. _openTaskCenter(appNames, options, statusObj);
  210. break;
  211. default:
  212. var uri = new URI(window.location.href);
  213. var optionsStr = uri.getData("option");
  214. var statusStr = uri.getData("status");
  215. window.location = o2.filterUrl("../x_desktop/appMobile.html?app=" + appNames + "&option=" + (optionsStr || "") + "&status=" + (statusStr || "") + ((layout.debugger) ? "&debugger" : ""));
  216. }
  217. };
  218. var _openWindow = function(url, par){
  219. var a = new Element("a", {
  220. "href": url,
  221. "target": par
  222. });
  223. a.click();
  224. a.destroy();
  225. };
  226. var _openApplicationPC = function (appNames, options, statusObj) {
  227. if (options) delete options.docTitle;
  228. var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  229. switch (appNames) {
  230. case "process.Work":
  231. var url = "../x_desktop/work.html".toURI();
  232. if (options.draft){
  233. url = "../x_desktop/app.html?" + par;
  234. }else{
  235. url = url.setData(options).toString();
  236. }
  237. var job = (options.jobid || options.jobId || options.job);
  238. if (job) url += ((url.indexOf("?")!=-1) ? "&" : "?") + "jobid="+job;
  239. url +=((layout.debugger) ? "&debugger" : "");
  240. if (layout.app.$openWithSelf) {
  241. return window.location = o2.filterUrl(url);
  242. } else {
  243. return window.open(o2.filterUrl(url), par);
  244. }
  245. break;
  246. case "cms.Document":
  247. // _openDocument(appNames, options, statusObj);
  248. var url = "../x_desktop/cmsdoc.html".toURI();
  249. url = url.setData(options).toString();
  250. url +=((layout.debugger) ? "&debugger" : "");
  251. if (layout.app.$openWithSelf) {
  252. return window.location = o2.filterUrl(url);
  253. } else {
  254. return window.open(o2.filterUrl(url), par);
  255. }
  256. break;
  257. // case "cms.Module":
  258. // _openCms(appNames, options, statusObj);
  259. // break;
  260. // case "Meeting":
  261. // _openMeeting(appNames, options, statusObj);
  262. // break;
  263. // case "Calendar":
  264. // _openCalendar(appNames, options, statusObj);
  265. // break;
  266. // case "process.TaskCenter":
  267. // _openTaskCenter(appNames, options, statusObj);
  268. // break;
  269. default:
  270. if (layout.app.$openWithSelf) {
  271. return window.location = o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : ""));
  272. } else {
  273. return window.open(o2.filterUrl("../x_desktop/app.html?" + par + ((layout.debugger) ? "&debugger" : "")), par);
  274. }
  275. }
  276. };
  277. layout.openApplication = function (e, appNames, options, statusObj, inBrowser, taskitem, notCurrent) {
  278. if (appNames.substring(0, 4) === "@url") {
  279. var url = appNames.replace(/\@url\:/i, "");
  280. var a = new Element("a", { "href": url, "target": "_blank" });
  281. a.click();
  282. a.destroy();
  283. a = null;
  284. return true;
  285. }
  286. if (layout.app) {
  287. if (layout.mobile) {
  288. _openApplicationMobile(appNames, options, statusObj);
  289. } else {
  290. return _openApplicationPC(appNames, options, statusObj);
  291. }
  292. } else {
  293. var appPath = appNames.split(".");
  294. var appName = appPath[appPath.length - 1];
  295. _requireApp(appNames, function (appNamespace) {
  296. var appId = (options && options.appId) ? options.appId : ((appNamespace.options.multitask) ? "" : appName);
  297. if (appId && layout.desktop.apps && layout.desktop.apps[appId]) {
  298. layout.desktop.apps[appId].setCurrent();
  299. } else {
  300. if (options) options.appId = appId;
  301. _createNewApplication(e, appNamespace, appName, (options || { "appId": appId }), statusObj, inBrowser, taskitem, notCurrent);
  302. }
  303. }.bind(this));
  304. }
  305. };
  306. layout.refreshApp = function (app) {
  307. var status = app.recordStatus();
  308. var uri = new URI(window.location.href);
  309. var appNames = uri.getData("app");
  310. var optionsStr = uri.getData("option");
  311. var statusStr = uri.getData("status");
  312. if (status) statusStr = JSON.encode(status);
  313. var port = uri.get("port");
  314. window.location = o2.filterUrl(uri.get("scheme") + "://" + uri.get("host") + ((port) ? ":" + port + "/" : "") + uri.get("directory ") + "?app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent(statusStr) + "&option=" + encodeURIComponent((optionsStr) ? JSON.encode(optionsStr) : "") + ((layout.debugger) ? "&debugger" : ""));
  315. };
  316. layout.load = function (appNames, options, statusObj) {
  317. layout.apps = [];
  318. layout.node = $("layout");
  319. var appName = appNames, m_status = statusObj, option = options;
  320. var topWindow = window.opener;
  321. if (topWindow) {
  322. try {
  323. if (!appName) appName = topWindow.layout.desktop.openBrowserApp;
  324. if (!m_status) m_status = topWindow.layout.desktop.openBrowserStatus;
  325. if (!option) option = topWindow.layout.desktop.openBrowserOption;
  326. } catch (e) { }
  327. }
  328. layout.openApplication(null, appName, option || {}, m_status);
  329. };
  330. })(layout);