WebSocket.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. MWF.xDesktop = MWF.xDesktop || {};
  2. MWF.xApplication = MWF.xApplication || {};
  3. MWF.require("MWF.xDesktop.Actions.RestActions", null, false);
  4. MWF.xDesktop.WebSocket = new Class({
  5. Implements: [Options, Events],
  6. options: {},
  7. initialize: function(options){
  8. var addressObj = layout.serviceAddressList["x_message_assemble_communicate"];
  9. var defaultPort = layout.config.app_protocol==='https' ? "443" : "80";
  10. var appPort = addressObj.port || window.location.port;
  11. var uri = new URI(window.location.href);
  12. var scheme = uri.get("scheme");
  13. var wsScheme = (scheme.toString().toLowerCase()==="https") ? "wss" : "ws";
  14. this.ws = wsScheme+"://"+addressObj.host+( (!appPort || appPort.toString()===defaultPort) ? "" : ":"+appPort)+addressObj.context+"/ws/collaboration";
  15. this.reConnect = true;
  16. this.checking = false;
  17. this.heartTimeout = 30000;
  18. this.checkingTimeout = 4000;
  19. this.heartMsg = "heartbeat";
  20. this.maxErrorCount = 10;
  21. this.errorCount = 0;
  22. // var addressObj = layout.desktop.serviceAddressList["x_collaboration_assemble_websocket"];
  23. // this.ws = "ws://"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+addressObj.context+"/ws/collaboration";
  24. //var ws = "ws://hbxa01.bf.ctc.com/x_collaboration_assemble_websocket/ws/collaboration";
  25. //使用轮询方式处理消息.....
  26. // this.webSocket = {
  27. // "readyState":"1",
  28. // "close": function(){},
  29. // "open": function(){}
  30. // };
  31. // window.setInterval(function(){
  32. // o2.Actions.get("")
  33. // }, 10000);
  34. ///*暂时不启用WebSocket了------------
  35. //this.ws = this.ws+"?x-token="+encodeURIComponent(Cookie.read("x-token"))+"&authorization="+encodeURIComponent(Cookie.read("x-token"));
  36. this.connect();
  37. },
  38. connect: function(){
  39. if (layout.config.webSocketEnable !== false){
  40. var ws = this.ws+"?"+o2.tokenName+"="+encodeURIComponent(layout.session.token);
  41. ws = o2.filterUrl(ws);
  42. try{
  43. this.webSocket = new WebSocket(ws);
  44. //this.webSocket = new WebSocket(this.ws);
  45. this.webSocket.onopen = function (e){this.onOpen(e);}.bind(this);
  46. this.webSocket.onclose = function (e){this.onClose(e);}.bind(this);
  47. this.webSocket.onmessage = function (e){this.onMessage(e);}.bind(this);
  48. this.webSocket.onerror = function (e){this.onError(e);}.bind(this);
  49. //---------------------------------*/
  50. }catch(e){
  51. //WebSocket.close();
  52. //this.webSocket = new WebSocket(this.ws);
  53. this.errorCount++;
  54. console.log("Unable to connect to the websocket server, will retry in "+(this.checkingTimeout/1000)+" seconds");
  55. this.checkRetry();
  56. // if (this.webSocket){
  57. // this.close();
  58. // //this.webSocket = new WebSocket(this.ws);
  59. // }
  60. }
  61. }
  62. },
  63. onOpen: function(e){
  64. this.errorCount = 0;
  65. console.log("websocket is open, You can receive system messages");
  66. this.heartbeat();
  67. //MWF.xDesktop.notice("success", {"x": "right", "y": "top"}, "websocket is open ...");
  68. },
  69. onClose: function(e){
  70. console.log("websocket is closed. ");
  71. //if (this.reConnect) this.checkRetry();
  72. //MWF.xDesktop.notice("success", {"x": "right", "y": "top"}, "websocket is closed ...");
  73. },
  74. onMessage: function(e){
  75. if (e.data){
  76. try{
  77. if (e.data===this.heartMsg){
  78. this.heartbeat();
  79. //console.log("get heartbeat...");
  80. return true;
  81. }
  82. var data = JSON.decode(e.data);
  83. debugger;
  84. switch (data.category){
  85. case "dialog":
  86. switch (data.type){
  87. case "text":
  88. this.receiveChatMessage(data);
  89. break;
  90. default:
  91. }
  92. break;
  93. default:
  94. switch (data.type){
  95. case "task":
  96. case "task_create":
  97. case "task_urge":
  98. case "task_expire":
  99. case "task_press":
  100. case "task_delete":
  101. this.receiveTaskMessage(data);
  102. break;
  103. case "read":
  104. case "read_create":
  105. this.receiveReadMessage(data);
  106. break;
  107. case "review":
  108. this.receiveReviewMessage(data);
  109. break;
  110. case "fileEditor":
  111. case "attachment_editor":
  112. case "attachment_editorCancel":
  113. case "attachment_editorModify":
  114. this.receiveFileEditorMessage(data);
  115. break;
  116. case "fileShare":
  117. case "attachment_share":
  118. case "attachment_shareCancel":
  119. this.receiveFileShareMessage(data);
  120. break;
  121. case "meetingInvite":
  122. case "meeting_invite":
  123. this.receiveMeetingInviteMessage(data);
  124. break;
  125. case "meetingDelete":
  126. case "meeting_delete":
  127. this.receiveMeetingDeleteInviteMessage(data);
  128. break;
  129. case "meetingCancel":
  130. case "meeting_cancel":
  131. this.receiveMeetingCancelMessage(data);
  132. break;
  133. case "meetingAccept":
  134. case "meeting_accept":
  135. this.receiveMeetingAcceptMessage(data);
  136. break;
  137. case "meetingReject":
  138. case "meeting_reject":
  139. this.receiveMeetingRejectMessage(data);
  140. break;
  141. case "attendanceAppealInvite":
  142. this.receiveAttendanceAppealInviteMessage(data);
  143. break;
  144. case "attendanceAppealAccept":
  145. this.receiveAttendanceAppealAcceptMessage(data);
  146. break;
  147. case "attendanceAppealReject":
  148. this.receiveAttendanceAppealRejectMessage(data);
  149. break;
  150. case "calendar_alarm":
  151. this.receiveCalendarAlarmMessage(data);
  152. break;
  153. case "teamwork_taskCreate":
  154. case "teamwork_taskUpdate":
  155. case "teamwork_taskDelelte":
  156. case "teamwork_taskOvertime":
  157. case "teamwork_taskChat":
  158. this.receiveTeamWorkMessage(data);
  159. break;
  160. case "custom_create":
  161. this.receiveCustomMessage(data);
  162. break;
  163. case "im_create":
  164. case "im_revoke":
  165. case "im_conv_update":
  166. case "im_conv_delete":
  167. this.receiveIMMessage(data);
  168. break;
  169. case "cms_publish" :
  170. this.receiveCMSPublishMessage(data);
  171. break;
  172. case "bbs_replyCreate" :
  173. this.receivBBSReplyCreateMessage(data);
  174. break;
  175. default:
  176. }
  177. }
  178. }catch(e){}
  179. }
  180. },
  181. onError: function(e){
  182. this.errorCount++;
  183. //console.log(e);
  184. console.log("Unable to connect to the websocket server, will retry in "+(this.checkingTimeout/1000)+" seconds.");
  185. this.checkRetry();
  186. //MWF.xDesktop.notice("success", {"x": "right", "y": "top"}, "websocket is error ...");
  187. },
  188. checkRetry: function(){
  189. if (this.serverCheck) window.clearTimeout(this.serverCheck);
  190. if (this.heartbeatCheck) window.clearTimeout(this.heartbeatCheck);
  191. if (this.errorCount < this.maxErrorCount) this.serverCheck = window.setTimeout(function(){
  192. this.retry();
  193. }.bind(this), this.checkingTimeout);
  194. },
  195. retry: function(){
  196. if (this.webSocket){
  197. this.close();
  198. }
  199. console.log("Retry connect to websocket server. ("+this.errorCount+"/"+this.maxErrorCount+")");
  200. this.connect();
  201. },
  202. close: function(){
  203. this.reConnect = false;
  204. if (this.webSocket) this.webSocket.close();
  205. //WebSocket.close();
  206. },
  207. send: function(msg){
  208. if (!this.webSocket || this.webSocket.readyState != 1) {
  209. if (this.serverCheck) window.clearTimeout(this.serverCheck);
  210. this.retry();
  211. }
  212. // try{
  213. this.webSocket.send(JSON.encode(msg));
  214. // }catch(e){
  215. // this.retry();
  216. // this.webSocket.send(JSON.encode(msg));
  217. // }
  218. },
  219. heartbeat: function(){
  220. if (this.serverCheck) window.clearTimeout(this.serverCheck);
  221. if (this.heartbeatCheck) window.clearTimeout(this.heartbeatCheck);
  222. this.heartbeatCheck = window.setTimeout(function(){
  223. this.sendHeartbeat(this.heartMsg);
  224. }.bind(this), this.heartTimeout);
  225. },
  226. sendHeartbeat: function(msg){
  227. if (!this.webSocket || this.webSocket.readyState != 1) {
  228. if (this.serverCheck) window.clearTimeout(this.serverCheck);
  229. this.retry();
  230. }
  231. try{
  232. //console.log("send heartbeat ...");
  233. this.webSocket.send(msg);
  234. this.checkRetry();
  235. }catch(e){
  236. //console.log("send heartbeat error !!!");
  237. if (this.serverCheck) window.clearTimeout(this.serverCheck);
  238. this.retry();
  239. //this.initialize();
  240. }
  241. },
  242. receiveCMSPublishMessage: function(data){
  243. var content = "<font style='color: #ea621f'>"+(data.body.creatorPerson||"").split("@")[0]+"</font>"+MWF.LP.desktop.messsage.publishDocument+data.body.title;
  244. var msg = {
  245. "subject": data.body.msgTitle?data.body.msgTitle:data.body.categoryName,
  246. "content": data.body.msgContent?data.body.msgContent:content
  247. };
  248. var messageItem = layout.desktop.message.addMessage(msg);
  249. var tooltipItem = layout.desktop.message.addTooltip(msg);
  250. tooltipItem.contentNode.addEvent("click", function(e){
  251. layout.desktop.message.hide();
  252. var appId = "cms.Document"+data.body.id;
  253. if ( layout.desktop.apps && layout.desktop.apps[appId] ) {
  254. layout.desktop.apps[appId].setCurrent();
  255. }else{
  256. var options = {"documentId": data.body.id, "appId": appId};
  257. layout.desktop.openApplication(e, "cms.Document", options);
  258. }
  259. });
  260. messageItem.contentNode.addEvent("click", function(e){
  261. layout.desktop.message.addUnread(-1);
  262. layout.desktop.message.hide();
  263. var appId = "cms.Document"+data.body.id;
  264. if ( layout.desktop.apps && layout.desktop.apps[appId] ) {
  265. layout.desktop.apps[appId].setCurrent();
  266. }else{
  267. var options = {"documentId": data.body.id, "appId": appId};
  268. layout.desktop.openApplication(e, "cms.Document", options);
  269. }
  270. });
  271. },
  272. receiveChatMessage: function(data){
  273. if (layout.desktop.widgets["IMIMWidget"]) layout.desktop.widgets["IMIMWidget"].receiveChatMessage(data);
  274. //if (layout.desktop.top.userPanel) layout.desktop.top.userPanel.receiveChatMessage(data);
  275. },
  276. openWork: function(id, e){
  277. o2.Actions.get("x_processplatform_assemble_surface").loadWorkV2(id, function(){
  278. var options = {"workId": id, "appId": "process.Work"+id};
  279. layout.desktop.openApplication(e, "process.Work", options);
  280. }.bind(this), function(){
  281. layout.desktop.openApplication(e, "process.workcenter", null, {
  282. "status": {
  283. "navi": "task"
  284. }
  285. });
  286. return true;
  287. }.bind(this));
  288. },
  289. receiveTaskMessage: function(data){
  290. var task = data.body;
  291. //var content = MWF.LP.desktop.messsage.receiveTask+"《"+task.title+"》, "+MWF.LP.desktop.messsage.activity+": <font style='color: #ea621f'>"+(task.activityName || "")+"</font>";
  292. var content = o2.txt(data.title);
  293. content += "<br/><font style='color: #333; font-weight: bold'>"+MWF.LP.desktop.messsage.appliction+": </font><font style='color: #ea621f'>"+o2.txt(task.applicationName)+"</font>; "+
  294. "<font style='color: #333; font-weight: bold'>"+MWF.LP.desktop.messsage.process+": </font><font style='color: #ea621f'>"+o2.txt(task.processName)+"</font>";
  295. var msg = {
  296. "subject": MWF.LP.desktop.messsage.taskMessage,
  297. "content": content
  298. };
  299. var messageItem = layout.desktop.message.addMessage(msg, data.body.startTime);
  300. var tooltipItem = layout.desktop.message.addTooltip(msg, data.body.startTime);
  301. tooltipItem.contentNode.addEvent("click", function(e){
  302. layout.desktop.message.hide();
  303. if( data.type !== "task_delete" )this.openWork(task.work,e);
  304. }.bind(this));
  305. messageItem.contentNode.addEvent("click", function(e){
  306. layout.desktop.message.addUnread(-1);
  307. layout.desktop.message.hide();
  308. if( data.type !== "task_delete" )this.openWork(task.work,e);
  309. }.bind(this));
  310. },
  311. receiveReadMessage: function(data){
  312. var read = data.body;
  313. //var content = MWF.LP.desktop.messsage.receiveRead+"《"+read.title+"》. ";
  314. var content = o2.txt(data.title);
  315. content += "<br/><font style='color: #333; font-weight: bold'>"+MWF.LP.desktop.messsage.appliction+": </font><font style='color: #ea621f'>"+o2.txt(read.applicationName)+"</font>; "+
  316. "<font style='color: #333; font-weight: bold'>"+MWF.LP.desktop.messsage.process+": </font><font style='color: #ea621f'>"+o2.txt(read.processName)+"</font>";
  317. var msg = {
  318. "subject": MWF.LP.desktop.messsage.readMessage,
  319. "content": content
  320. };
  321. var messageItem = layout.desktop.message.addMessage(msg, data.body.startTime);
  322. var tooltipItem = layout.desktop.message.addTooltip(msg, data.body.startTime);
  323. tooltipItem.contentNode.addEvent("click", function(e){
  324. layout.desktop.message.hide();
  325. this.openWork(read.work || read.workCompleted,e);
  326. }.bind(this));
  327. messageItem.contentNode.addEvent("click", function(e){
  328. layout.desktop.message.addUnread(-1);
  329. layout.desktop.message.hide();
  330. this.openWork(read.work || read.workCompleted,e);
  331. }.bind(this));
  332. },
  333. receiveCustomMessage: function(data){
  334. var text = o2.typeOf(data.body) === "string" ? data.body : data.title;
  335. var content = "<font style='color: #333; font-weight: bold'>"+MWF.LP.desktop.messsage.customMessage+":</font>"+o2.txt(text);
  336. var msg = {
  337. "subject": MWF.LP.desktop.messsage.customMessageTitle,
  338. "content": content
  339. };
  340. var messageItem = layout.desktop.message.addMessage(msg);
  341. var tooltipItem = layout.desktop.message.addTooltip(msg);
  342. },
  343. // im消息处理器 messageType 消息类型,如im_revoke im_create , callback处理函数
  344. addImListener: function(messageType, callback) {
  345. this.imListenerMap = this.imListenerMap || {};
  346. this.imListenerMap[messageType] = callback;
  347. },
  348. /// im消息处理
  349. receiveIMMessage: function(data){
  350. var imBody = data.body;
  351. // 更新会话或删除会话
  352. if (data.type === "im_conv_update" || data.type === "im_conv_delete") {
  353. // 执行im callback 刷新页面信息
  354. if (this.imListenerMap && this.imListenerMap["im_conversation"] && typeof this.imListenerMap["im_conversation"] == 'function') {
  355. this.imListenerMap["im_conversation"](imBody);
  356. }
  357. return;
  358. }
  359. // 撤回消息
  360. if (data.type == "im_revoke") {
  361. // 执行im callback 刷新页面信息
  362. if (this.imListenerMap && this.imListenerMap["im_revoke"] && typeof this.imListenerMap["im_revoke"] == 'function') {
  363. this.imListenerMap["im_revoke"](imBody);
  364. }
  365. return;
  366. }
  367. // im_create 暂时不变
  368. if (data.type == "im_create") {
  369. // 系统消息
  370. var jsonBody = imBody.body;
  371. var conversationId = imBody.conversationId;
  372. var body = JSON.parse(jsonBody);
  373. var msgBody = body.body; //默认text 文本消息
  374. if (body.type && body.type == "emoji") { //表情 消息
  375. msgBody = "["+MWF.LP.desktop.messsage.emoji+"]";
  376. } else if (body.type == "process") {
  377. msgBody = "["+MWF.LP.desktop.messsage.processWork+"]";
  378. } else if (body.type == "cms") {
  379. msgBody = "["+MWF.LP.desktop.messsage.cmsDoc+"]";
  380. }
  381. var content = "<font style='color: #333; font-weight: bold'>"+o2.txt(data.title)+"</font>: "+o2.txt(msgBody);
  382. var msg = {
  383. "subject": MWF.LP.desktop.messsage.customMessageTitle,
  384. "content": content
  385. };
  386. var messageItem = layout.desktop.message.addMessage(msg);
  387. var options = {"conversationId": conversationId};
  388. messageItem.contentNode.addEvent("click", function(e){
  389. layout.desktop.message.addUnread(-1);
  390. layout.desktop.message.hide();
  391. layout.desktop.openApplication(e, "IMV2", options);
  392. }.bind(this));
  393. var tooltipItem = layout.desktop.message.addTooltip(msg);
  394. tooltipItem.contentNode.addEvent("click", function(e){
  395. layout.desktop.message.hide();
  396. layout.desktop.openApplication(e, "IMV2", options);
  397. }.bind(this));
  398. // 执行im callback 刷新页面信息
  399. if (this.imListenerMap && this.imListenerMap["im_create"] && typeof this.imListenerMap["im_create"] == 'function') {
  400. this.imListenerMap["im_create"](imBody);
  401. }
  402. return;
  403. }
  404. },
  405. receiveReviewMessage: function(data){
  406. var content = MWF.LP.desktop.messsage.receiveReview+"《"+o2.txt(data.title)+"》. ";
  407. content += "<br/><font style='color: #333; font-weight: bold'>"+MWF.LP.desktop.messsage.appliction+": </font><font style='color: #ea621f'>"+o2.txt(data.applicationName)+"</font>; "+
  408. "<font style='color: #333; font-weight: bold'>"+MWF.LP.desktop.messsage.process+": </font><font style='color: #ea621f'>"+o2.txt(data.processName)+"</font>";
  409. var msg = {
  410. "subject": MWF.LP.desktop.messsage.reviewMessage,
  411. "content": content
  412. };
  413. var messageItem = layout.desktop.message.addMessage(msg, data.body.startTime);
  414. var tooltipItem = layout.desktop.message.addTooltip(msg, data.body.startTime);
  415. tooltipItem.contentNode.addEvent("click", function(e){
  416. layout.desktop.message.hide();
  417. layout.desktop.openApplication(e, "process.TaskCenter", null, {
  418. "status": {
  419. "navi": "review"
  420. }
  421. });
  422. });
  423. messageItem.contentNode.addEvent("click", function(e){
  424. layout.desktop.message.addUnread(-1);
  425. layout.desktop.message.hide();
  426. layout.desktop.openApplication(e, "process.TaskCenter", null, {
  427. "status": {
  428. "navi": "review"
  429. }
  430. });
  431. });
  432. },
  433. receiveFileEditorMessage: function(data){
  434. var content = "<font style='color: #ea621f; font-weight: bold'>"+MWF.name.cn(data.body.person)+"</font> "+MWF.LP.desktop.messsage.receiveFileEditor+"“"+o2.txt(data.body.name)+"”. ";
  435. var msg = {
  436. "subject": MWF.LP.desktop.messsage.fileEditorMessage,
  437. "content": content
  438. };
  439. var messageItem = layout.desktop.message.addMessage(msg, ((data.body) ? data.body.startTime : ""));
  440. var tooltipItem = layout.desktop.message.addTooltip(msg, ((data.body) ? data.body.startTime : ""));
  441. tooltipItem.contentNode.addEvent("click", function(e){
  442. layout.desktop.message.hide();
  443. layout.desktop.openApplication(e, "File", null, {
  444. "status": {
  445. "tab": "editor",
  446. "node": data.person
  447. }
  448. });
  449. });
  450. messageItem.contentNode.addEvent("click", function(e){
  451. layout.desktop.message.addUnread(-1);
  452. layout.desktop.message.hide();
  453. layout.desktop.openApplication(e, "File", null, {
  454. "status": {
  455. "tab": "editor",
  456. "node": data.person
  457. }
  458. });
  459. });
  460. },
  461. receiveFileShareMessage: function(data){
  462. var content = "<font style='color: #ea621f; font-weight: bold'>"+MWF.name.cn(data.body.person)+"</font> "+MWF.LP.desktop.messsage.receiveFileShare+"“"+o2.txt(data.body.name)+"”. ";
  463. var msg = {
  464. "subject": MWF.LP.desktop.messsage.fileShareMessage,
  465. "content": content
  466. };
  467. var messageItem = layout.desktop.message.addMessage(msg, ((data.body) ? data.body.createTime : ""));
  468. var tooltipItem = layout.desktop.message.addTooltip(msg, ((data.body) ? data.body.createTime : ""));
  469. tooltipItem.contentNode.addEvent("click", function(e){
  470. layout.desktop.message.hide();
  471. //应用市场中的云文件,门户cloudFile
  472. o2.Actions.load("x_portal_assemble_surface").PortalAction.get("cloudFile", function () {
  473. layout.desktop.openApplication(e, "portal.Portal", {
  474. portalId : "cloudFile"
  475. });
  476. }, function(){
  477. layout.desktop.openApplication(e, "File", null, {
  478. "status": {
  479. "tab": "share",
  480. "node": data.person
  481. }
  482. });
  483. })
  484. });
  485. messageItem.contentNode.addEvent("click", function(e){
  486. layout.desktop.message.addUnread(-1);
  487. layout.desktop.message.hide();
  488. layout.desktop.openApplication(e, "File", null, {
  489. "status": {
  490. "tab": "share",
  491. "node": data.person
  492. }
  493. });
  494. });
  495. },
  496. getMeeting: function(data, callback){
  497. //this.action = new MWF.xDesktop.Actions.RestActions("/Actions/action.json", "x_meeting_assemble_control", "x_component_Meeting");
  498. //var action = new MWF.xDesktop.Actions.RestActions("/Actions/action.json", "x_meeting_assemble_control", "x_component_Meeting");
  499. if( data.body && typeOf( data.body ) === "object" ){
  500. var data = data.body;
  501. MWF.Actions.get("x_meeting_assemble_control").getRoom(data.room, function(roomJson){
  502. data.roomName = roomJson.data.name;
  503. MWF.Actions.get("x_meeting_assemble_control").getBuilding(roomJson.data.building, function(buildingJson){
  504. data.buildingName = buildingJson.data.name;
  505. if (callback) callback(data);
  506. }.bind(this));
  507. }.bind(this));
  508. }else{
  509. MWF.Actions.get("x_meeting_assemble_control").getMeeting(data.metting, function(json){
  510. var data = json.data;
  511. MWF.Actions.get("x_meeting_assemble_control").getRoom(data.room, function(roomJson){
  512. data.roomName = roomJson.data.name;
  513. MWF.Actions.get("x_meeting_assemble_control").getBuilding(roomJson.data.building, function(buildingJson){
  514. data.buildingName = buildingJson.data.name;
  515. if (callback) callback(data);
  516. }.bind(this));
  517. }.bind(this));
  518. }.bind(this));
  519. }
  520. },
  521. receiveMeetingInviteMessage: function(data){
  522. this.getMeeting(data, function(meeting){
  523. var content = MWF.LP.desktop.messsage.meetingInvite;
  524. content = content.replace(/{person}/g, MWF.name.cn(meeting.applicant));
  525. var date = Date.parse(meeting.startTime).format("%Y-%m-%d- %H:%M");
  526. content = content.replace(/{date}/g, date);
  527. content = content.replace(/{subject}/g, o2.txt(meeting.subject));
  528. content = content.replace(/{addr}/g, o2.txt(meeting.roomName+"("+meeting.buildingName+")"));
  529. var msg = {
  530. "subject": MWF.LP.desktop.messsage.meetingInviteMessage,
  531. "content": content
  532. };
  533. var messageItem = layout.desktop.message.addMessage(msg, ((data.body) ? data.body.startTime : ""));
  534. var tooltipItem = layout.desktop.message.addTooltip(msg, ((data.body) ? data.body.startTime : ""));
  535. tooltipItem.contentNode.addEvent("click", function(e){
  536. layout.desktop.message.hide();
  537. layout.desktop.openApplication(e, "Meeting", null);
  538. });
  539. messageItem.contentNode.addEvent("click", function(e){
  540. layout.desktop.message.addUnread(-1);
  541. layout.desktop.message.hide();
  542. layout.desktop.openApplication(e, "Meeting", null);
  543. });
  544. }.bind(this));
  545. },
  546. receiveMeetingDeleteInviteMessage: function(data){
  547. this.getMeeting(data, function(meeting){
  548. var content = MWF.LP.desktop.messsage.meetingDeleteInvite;
  549. content = content.replace(/{person}/g, MWF.name.cn(meeting.applicant));
  550. var date = Date.parse(meeting.startTime).format("%Y-%m-%d- %H:%M");
  551. content = content.replace(/{date}/g, date);
  552. content = content.replace(/{subject}/g, o2.txt(meeting.subject));
  553. content = content.replace(/{addr}/g, o2.txt(meeting.roomName+"("+meeting.buildingName+")"));
  554. var msg = {
  555. "subject": MWF.LP.desktop.messsage.meetingDeleteInviteMessage,
  556. "content": content
  557. };
  558. var messageItem = layout.desktop.message.addMessage(msg, ((data.body) ? data.body.startTime : ""));
  559. var tooltipItem = layout.desktop.message.addTooltip(msg, ((data.body) ? data.body.startTime : ""));
  560. tooltipItem.contentNode.addEvent("click", function(e){
  561. layout.desktop.message.hide();
  562. layout.desktop.openApplication(e, "Meeting", null);
  563. });
  564. messageItem.contentNode.addEvent("click", function(e){
  565. layout.desktop.message.addUnread(-1);
  566. layout.desktop.message.hide();
  567. layout.desktop.openApplication(e, "Meeting", null);
  568. });
  569. }.bind(this));
  570. },
  571. receiveMeetingCancelMessage: function(data){
  572. this.getMeeting(data, function(meeting){
  573. var content = MWF.LP.desktop.messsage.meetingCancel;
  574. content = content.replace(/{person}/g, MWF.name.cn(meeting.applicant));
  575. var date = Date.parse(meeting.startTime).format("%Y-%m-%d- %H:%M");
  576. content = content.replace(/{date}/g, date);
  577. content = content.replace(/{subject}/g, o2.txt(meeting.subject));
  578. content = content.replace(/{addr}/g, o2.txt(meeting.roomName+"("+meeting.buildingName+")"));
  579. var msg = {
  580. "subject": MWF.LP.desktop.messsage.meetingCancelMessage,
  581. "content": content
  582. };
  583. var messageItem = layout.desktop.message.addMessage(msg, ((data.body) ? data.body.startTime : ""));
  584. var tooltipItem = layout.desktop.message.addTooltip(msg, ((data.body) ? data.body.startTime : ""));
  585. tooltipItem.contentNode.addEvent("click", function(e){
  586. layout.desktop.message.hide();
  587. layout.desktop.openApplication(e, "Meeting", null);
  588. });
  589. messageItem.contentNode.addEvent("click", function(e){
  590. layout.desktop.message.addUnread(-1);
  591. layout.desktop.message.hide();
  592. layout.desktop.openApplication(e, "Meeting", null);
  593. });
  594. }.bind(this));
  595. },
  596. receiveMeetingAcceptMessage: function(data){
  597. this.getMeeting(data, function(meeting){
  598. var content = MWF.LP.desktop.messsage.meetingAccept;
  599. //content = content.replace(/{person}/g, MWF.name.cn(meeting.applicant));
  600. content = content.replace(/{person}/g, MWF.name.cn(data.body.fromPerson));
  601. var date = Date.parse(meeting.startTime).format("%Y-%m-%d- %H:%M");
  602. content = content.replace(/{date}/g, date);
  603. content = content.replace(/{subject}/g, o2.txt(meeting.subject));
  604. content = content.replace(/{addr}/g, o2.txt(meeting.roomName+"("+meeting.buildingName+")"));
  605. var msg = {
  606. "subject": MWF.LP.desktop.messsage.meetingAcceptMessage,
  607. "content": content
  608. };
  609. var messageItem = layout.desktop.message.addMessage(msg, ((data.body) ? data.body.startTime : ""));
  610. var tooltipItem = layout.desktop.message.addTooltip(msg, ((data.body) ? data.body.startTime : ""));
  611. tooltipItem.contentNode.addEvent("click", function(e){
  612. layout.desktop.message.hide();
  613. layout.desktop.openApplication(e, "Meeting", null);
  614. });
  615. messageItem.contentNode.addEvent("click", function(e){
  616. layout.desktop.message.addUnread(-1);
  617. layout.desktop.message.hide();
  618. layout.desktop.openApplication(e, "Meeting", null);
  619. });
  620. }.bind(this));
  621. },
  622. receiveMeetingRejectMessage: function(data){
  623. this.getMeeting(data, function(meeting){
  624. var content = MWF.LP.desktop.messsage.meetingReject;
  625. //content = content.replace(/{person}/g, MWF.name.cn(meeting.applicant));
  626. content = content.replace(/{person}/g, MWF.name.cn(data.body.fromPerson));
  627. var date = Date.parse(meeting.startTime).format("%Y-%m-%d- %H:%M");
  628. content = content.replace(/{date}/g, date);
  629. content = content.replace(/{subject}/g, o2.txt(meeting.subject));
  630. content = content.replace(/{addr}/g, o2.txt(meeting.roomName+"("+meeting.buildingName+")"));
  631. var msg = {
  632. "subject": MWF.LP.desktop.messsage.meetingRejectMessage,
  633. "content": content
  634. };
  635. var messageItem = layout.desktop.message.addMessage(msg, ((data.body) ? data.body.startTime : ""));
  636. var tooltipItem = layout.desktop.message.addTooltip(msg, ((data.body) ? data.body.startTime : ""));
  637. tooltipItem.contentNode.addEvent("click", function(e){
  638. layout.desktop.message.hide();
  639. layout.desktop.openApplication(e, "Meeting", null);
  640. });
  641. messageItem.contentNode.addEvent("click", function(e){
  642. layout.desktop.message.addUnread(-1);
  643. layout.desktop.message.hide();
  644. layout.desktop.openApplication(e, "Meeting", null);
  645. });
  646. }.bind(this));
  647. },
  648. receiveAttendanceAppealInviteMessage : function(data){
  649. var content = MWF.LP.desktop.messsage.attendanceAppealInvite;
  650. content = content.replace(/{subject}/g, o2.txt(data.subject));
  651. var msg = {
  652. "subject": MWF.LP.desktop.messsage.attendanceAppealInviteMessage,
  653. "content": content
  654. };
  655. var messageItem = layout.desktop.message.addMessage(msg);
  656. var tooltipItem = layout.desktop.message.addTooltip(msg);
  657. tooltipItem.contentNode.addEvent("click", function(e){
  658. layout.desktop.message.hide();
  659. layout.desktop.openApplication(e, "Attendance", {"curNaviId":"13"});
  660. });
  661. messageItem.contentNode.addEvent("click", function(e){
  662. layout.desktop.message.addUnread(-1);
  663. layout.desktop.message.hide();
  664. layout.desktop.openApplication(e, "Attendance", {"curNaviId":"13"});
  665. });
  666. },
  667. receiveAttendanceAppealAcceptMessage : function(data){
  668. var content = MWF.LP.desktop.messsage.attendanceAppealAccept;
  669. content = content.replace(/{subject}/g, o2.txt(data.subject));
  670. var msg = {
  671. "subject": MWF.LP.desktop.messsage.attendanceAppealAcceptMessage,
  672. "content": content
  673. };
  674. var messageItem = layout.desktop.message.addMessage(msg);
  675. var tooltipItem = layout.desktop.message.addTooltip(msg);
  676. tooltipItem.contentNode.addEvent("click", function(e){
  677. layout.desktop.message.hide();
  678. layout.desktop.openApplication(e, "Attendance", {"curNaviId":"12"});
  679. });
  680. messageItem.contentNode.addEvent("click", function(e){
  681. layout.desktop.message.addUnread(-1);
  682. layout.desktop.message.hide();
  683. layout.desktop.openApplication(e, "Attendance", {"curNaviId":"12"});
  684. });
  685. },
  686. receiveAttendanceAppealRejectMessage : function(data){
  687. var content = MWF.LP.desktop.messsage.attendanceAppealReject;
  688. content = content.replace(/{subject}/g, o2.txt(data.subject));
  689. var msg = {
  690. "subject": MWF.LP.desktop.messsage.attendanceAppealRejectMessage,
  691. "content": content
  692. };
  693. var messageItem = layout.desktop.message.addMessage(msg);
  694. var tooltipItem = layout.desktop.message.addTooltip(msg);
  695. tooltipItem.contentNode.addEvent("click", function(e){
  696. layout.desktop.message.hide();
  697. layout.desktop.openApplication(e, "Attendance", {"curNaviId":"12"});
  698. });
  699. messageItem.contentNode.addEvent("click", function(e){
  700. layout.desktop.message.addUnread(-1);
  701. layout.desktop.message.hide();
  702. layout.desktop.openApplication(e, "Attendance", {"curNaviId":"12"});
  703. });
  704. },
  705. receiveCalendarAlarmMessage: function(data){
  706. var content = MWF.LP.desktop.messsage.canlendarAlarm;
  707. content = content.replace(/{title}/g, o2.txt(data.title));
  708. var msg = {
  709. "subject": MWF.LP.desktop.messsage.canlendarAlarmMessage,
  710. "content": content
  711. };
  712. var messageItem = layout.desktop.message.addMessage(msg);
  713. var tooltipItem = layout.desktop.message.addTooltip(msg);
  714. tooltipItem.contentNode.addEvent("click", function(e){
  715. layout.desktop.message.hide();
  716. if ( layout.desktop.apps && layout.desktop.apps["Calendar"] ) {
  717. if( layout.desktop.apps["Calendar"].openEvent ){
  718. layout.desktop.apps["Calendar"].setCurrent();
  719. layout.desktop.apps["Calendar"].openEvent( data.body.id );
  720. }else if(layout.desktop.apps["Calendar"].options){
  721. layout.desktop.apps["Calendar"].options.eventId = data.body.id;
  722. layout.desktop.apps["Calendar"].setCurrent();
  723. }else{
  724. layout.desktop.openApplication(e, "Calendar", {"eventId": data.body.id });
  725. }
  726. }else{
  727. layout.desktop.openApplication(e, "Calendar", {"eventId": data.body.id });
  728. }
  729. });
  730. messageItem.contentNode.addEvent("click", function(e){
  731. layout.desktop.message.addUnread(-1);
  732. layout.desktop.message.hide();
  733. if ( layout.desktop.apps && layout.desktop.apps["Calendar"] ) {
  734. if( layout.desktop.apps["Calendar"].openEvent ){
  735. layout.desktop.apps["Calendar"].setCurrent();
  736. layout.desktop.apps["Calendar"].openEvent( data.body.id );
  737. }else if(layout.desktop.apps["Calendar"].options){
  738. layout.desktop.apps["Calendar"].options.eventId = data.body.id;
  739. layout.desktop.apps["Calendar"].setCurrent();
  740. }else{
  741. layout.desktop.openApplication(e, "Calendar", {"eventId": data.body.id });
  742. }
  743. }else{
  744. layout.desktop.openApplication(e, "Calendar", {"eventId": data.body.id });
  745. }
  746. });
  747. },
  748. receiveTeamWorkMessage: function(data){
  749. var task = data.body;
  750. //var content = MWF.LP.desktop.messsage.receiveTask+"《"+task.title+"》, "+MWF.LP.desktop.messsage.activity+": <font style='color: #ea621f'>"+(task.activityName || "")+"</font>";
  751. var content = o2.txt(data.title);
  752. //content += "<br/><font style='color: #333; font-weight: bold'>"+MWF.LP.desktop.messsage.teamwork.creatorPerson+": </font><font style='color: #ea621f'>"+task.creatorPerson+"</font>; "+
  753. // "<font style='color: #333; font-weight: bold'>"+MWF.LP.desktop.messsage.teamwork.executor+": </font><font style='color: #ea621f'>"+task.executor+"</font>";
  754. var msg = {
  755. "subject": task.name,
  756. "content": content
  757. };
  758. var messageItem = layout.desktop.message.addMessage(msg);
  759. var tooltipItem = layout.desktop.message.addTooltip(msg);
  760. tooltipItem.contentNode.addEvent("click", function(e){
  761. layout.desktop.message.hide();
  762. var options = {"taskId": task.id, "projectId": task.project};
  763. layout.desktop.openApplication(e, "TeamWork.Task", options);
  764. }.bind(this));
  765. messageItem.contentNode.addEvent("click", function(e){
  766. layout.desktop.message.addUnread(-1);
  767. layout.desktop.message.hide();
  768. var options = {"taskId": task.id, "projectId": task.project};
  769. layout.desktop.openApplication(e, "TeamWork.Task", options);
  770. }.bind(this));
  771. },
  772. receiveBBSSubjectCreateMessage: function (data) {
  773. var content = MWF.LP.desktop.messsage.canlendarAlarm;
  774. content = content.replace(/{title}/g, o2.txt(data.title));
  775. var msg = {
  776. "subject": MWF.LP.desktop.messsage.canlendarAlarmMessage,
  777. "content": content
  778. };
  779. var messageItem = layout.desktop.message.addMessage(msg);
  780. var tooltipItem = layout.desktop.message.addTooltip(msg);
  781. tooltipItem.contentNode.addEvent("click", function(e){
  782. layout.desktop.message.hide();
  783. if ( layout.desktop.apps && layout.desktop.apps["Calendar"] ) {
  784. if( layout.desktop.apps["Calendar"].openEvent ){
  785. layout.desktop.apps["Calendar"].setCurrent();
  786. layout.desktop.apps["Calendar"].openEvent( data.body.id );
  787. }else if(layout.desktop.apps["Calendar"].options){
  788. layout.desktop.apps["Calendar"].options.eventId = data.body.id;
  789. layout.desktop.apps["Calendar"].setCurrent();
  790. }else{
  791. layout.desktop.openApplication(e, "Calendar", {"eventId": data.body.id });
  792. }
  793. }else{
  794. layout.desktop.openApplication(e, "Calendar", {"eventId": data.body.id });
  795. }
  796. });
  797. messageItem.contentNode.addEvent("click", function(e){
  798. layout.desktop.message.addUnread(-1);
  799. layout.desktop.message.hide();
  800. if ( layout.desktop.apps && layout.desktop.apps["Calendar"] ) {
  801. if( layout.desktop.apps["Calendar"].openEvent ){
  802. layout.desktop.apps["Calendar"].setCurrent();
  803. layout.desktop.apps["Calendar"].openEvent( data.body.id );
  804. }else if(layout.desktop.apps["Calendar"].options){
  805. layout.desktop.apps["Calendar"].options.eventId = data.body.id;
  806. layout.desktop.apps["Calendar"].setCurrent();
  807. }else{
  808. layout.desktop.openApplication(e, "Calendar", {"eventId": data.body.id });
  809. }
  810. }else{
  811. layout.desktop.openApplication(e, "Calendar", {"eventId": data.body.id });
  812. }
  813. });
  814. },
  815. receivBBSReplyCreateMessage: function (data) {
  816. debugger;
  817. var content = MWF.LP.desktop.messsage.bbsReplyCreate;
  818. content = content.replace(/{title}/g, (data.body.createPerson||"").split("@")[0] + o2.txt(data.title));
  819. var msg = {
  820. "subject": MWF.LP.desktop.messsage.bbsReplyCreateMessage,
  821. "content": content
  822. };
  823. var messageItem = layout.desktop.message.addMessage(msg);
  824. var tooltipItem = layout.desktop.message.addTooltip(msg);
  825. tooltipItem.contentNode.addEvent("click", function(e){
  826. layout.desktop.message.hide();
  827. var appId = "ForumDocument" + data.body.subjectId;
  828. if ( layout.desktop.apps && layout.desktop.apps[appId] ) {
  829. layout.desktop.apps[appId].setCurrent();
  830. }else{
  831. layout.desktop.openApplication(e, "ForumDocument", {"id": data.body.subjectId, "isEdited": false });
  832. }
  833. });
  834. messageItem.contentNode.addEvent("click", function(e){
  835. layout.desktop.message.addUnread(-1);
  836. layout.desktop.message.hide();
  837. var appId = "ForumDocument" + data.body.subjectId;
  838. if ( layout.desktop.apps && layout.desktop.apps[appId] ) {
  839. layout.desktop.apps[appId].setCurrent();
  840. }else{
  841. layout.desktop.openApplication(e, "ForumDocument", {"id": data.body.subjectId, "isEdited": false });
  842. }
  843. });
  844. }
  845. });