base.js 17 KB

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