UserPanel.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. MWF.xDesktop = MWF.xDesktop || {};
  2. MWF.xDesktop.requireApp("Selector", "Actions.RestActions", null, false);
  3. MWF.xDesktop.UserPanel = new Class({
  4. Extends: MWF.widget.Common,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function(container, options){
  10. this.setOptions(options);
  11. this.container = container;
  12. this.path = MWF.defaultPath+"/xDesktop/$UserPanel/";
  13. this.cssPath = MWF.defaultPath+"/xDesktop/$UserPanel/"+this.options.style+"/css.wcss";
  14. this.users = {};
  15. this.isShow = false;
  16. this._loadCss();
  17. },
  18. changStyle: function(style){
  19. this.setOptions({"style": style});
  20. this.cssPath = MWF.defaultPath+"/xDesktop/$UserPanel/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.node.setStyles(this.css.panelNode);
  23. this.titleNode.setStyles(this.css.titleNode);
  24. this.userInforNode.setStyles(this.css.userInforNode);
  25. this.userSearchNode.setStyles(this.css.userSearchNode);
  26. this.userListNode.setStyles(this.css.userListNode);
  27. this.userMenuNode.setStyles(this.css.userMenuNode);
  28. this.show();
  29. },
  30. load: function(){
  31. this.node = new Element("div#userpanel", {"styles": this.css.panelNode});
  32. this.titleNode = new Element("div", {"styles": this.css.titleNode}).inject(this.node);
  33. this.userInforNode = new Element("div", {"styles": this.css.userInforNode}).inject(this.node);
  34. this.userSearchNode = new Element("div", {"styles": this.css.userSearchNode}).inject(this.node);
  35. this.userListNode = new Element("div", {"styles": this.css.userListNode}).inject(this.node);
  36. this.userMenuNode = new Element("div", {"styles": this.css.userMenuNode}).inject(this.node);
  37. //this.node.addEvent("click", function(){
  38. // this.show();
  39. //}.bind(this));
  40. this.createTitle();
  41. this.createUserInfor();
  42. this.createSearch();
  43. this.createUserList();
  44. this.createBottomMenu();
  45. window.setInterval(function(){
  46. if (this.isShow) this.checkOnline();
  47. }.bind(this), 120000);
  48. },
  49. checkOnline: function(){
  50. Object.each(this.users, function(user){
  51. if (!this.onlineAction) this.onlineAction = new MWF.xDesktop.Actions.RestActions("/xDesktop/Actions/action.json", "x_collaboration_assemble_websocket");
  52. this.onlineAction.invoke({"name": "personOnline", "parameter": {"person": user.name}, "success": function(json){
  53. if (user.data.status != json.data.status){
  54. var icon = (user.data.icon) ? "data:image/png;base64,"+user.data.icon : "";
  55. if (!icon){
  56. if (user.data.genderType=="f"){
  57. icon = MWF.defaultPath+"/xDesktop/$UserPanel/default/icon/female.png";
  58. }else{
  59. icon = MWF.defaultPath+"/xDesktop/$UserPanel/default/icon/man.png";
  60. }
  61. }
  62. if (json.data.status!="offline"){
  63. user.userIconNode.set("src", icon);
  64. user.node.inject(user.onlineContainer);
  65. }else{
  66. user.userIconNode.set("src", MWF.grayscale(icon));
  67. user.node.inject(user.offlineContainer);
  68. }
  69. user.data.status = json.data.status
  70. }
  71. }.bind(this)});
  72. }.bind(this));
  73. },
  74. createBottomMenu: function(){
  75. // this.userConfigNode = new Element("div", {"styles": this.css.userConfigNode}).inject(this.userMenuNode);
  76. // this.userLogoutNode = new Element("div", {"styles": this.css.userLogoutNode}).inject(this.userMenuNode);
  77. },
  78. createTitle: function(){
  79. this.closeAction = new Element("div", {"styles": this.css.closeActionNode}).inject(this.titleNode);
  80. this.closeAction.addEvent("click", function(e){
  81. this.hide();
  82. e.stopPropagation();
  83. }.bind(this));
  84. },
  85. createUserInfor: function(){
  86. this.userIconAreaNode = new Element("div", {"styles": this.css.userIconAreaNode}).inject(this.userInforNode);
  87. this.userIconNode = new Element("img", {"styles": this.css.userIconNode}).inject(this.userIconAreaNode);
  88. this.userTextInforNode = new Element("div", {"styles": this.css.userTextInforNode}).inject(this.userInforNode);
  89. this.userNameInforNode = new Element("div", {"styles": this.css.userNameInforNode}).inject(this.userTextInforNode);
  90. this.userNameTextInforNode = new Element("div", {"styles": this.css.userNameTextInforNode}).inject(this.userNameInforNode);
  91. this.userDutyTextInforNode = new Element("div", {"styles": this.css.userDutyTextInforNode}).inject(this.userNameInforNode);
  92. this.userSignInforNode = new Element("div", {"styles": this.css.userSignInforNode}).inject(this.userTextInforNode);
  93. if (!this.userAction) this.userAction = new MWF.xApplication.Selector.Actions.RestActions();
  94. this.userAction.getPersonComplex(function(json){
  95. if (!json.data) json.data = {"display": layout.desktop.session.user.name, "name": layout.desktop.session.user.name, "identityList": []};
  96. this.owner = json.data;
  97. if (json.data.icon){
  98. this.userIconNode.set("src", "data:image/png;base64,"+json.data.icon+"");
  99. }else{
  100. if (json.data.genderType=="f"){
  101. this.userIconNode.set("src", ""+MWF.defaultPath+"/xDesktop/$UserPanel/default/icon/female.png");
  102. }else{
  103. this.userIconNode.set("src", ""+MWF.defaultPath+"/xDesktop/$UserPanel/default/icon/man.png");
  104. }
  105. }
  106. this.userNameTextInforNode.set("text", json.data.display);
  107. var departments = [];
  108. json.data.identityList.each(function(id){
  109. departments.push(id.department);
  110. }.bind(this));
  111. var dutys = [];
  112. //json.data.companyDutyList.each(function(duty){
  113. // dutys.push(duty.name);
  114. //}.bind(this));
  115. //json.data.departmentDutyList.each(function(duty){
  116. // dutys.push(duty.name);
  117. //}.bind(this));
  118. var text = (dutys.length) ? departments.join(", ")+ "["+ dutys.join(", ")+"]" : departments.join(", ");
  119. this.userDutyTextInforNode.set("text", text);
  120. this.userSignInforNode.set("text", json.data.signature || MWF.LP.desktop.nosign);
  121. }.bind(this), null, layout.desktop.session.user.name);
  122. },
  123. createSearch: function(){
  124. this.searchInput = new Element("input", {
  125. "styles": this.css.searchInput,
  126. "type": "text",
  127. "value": MWF.LP.desktop.searchUser
  128. }).inject(this.userSearchNode);
  129. this.searchInput.addEvents({
  130. "focus": function(){ if (this.searchInput.get("value")==MWF.LP.desktop.searchUser) this.searchInput.set("value", "");}.bind(this),
  131. "blur": function(){ if (!this.searchInput.get("value")) this.searchInput.set("value", MWF.LP.desktop.searchUser);}.bind(this),
  132. "keydown": function(e){ if (e.code==13) this.doSearch(); }.bind(this)
  133. });
  134. },
  135. doSearch: function(){
  136. var key = this.searchInput.get("value");
  137. if (key){
  138. this.userListSearchTab.click();
  139. if (!this.userAction) this.userAction = new MWF.xApplication.Selector.Actions.RestActions();
  140. this.userAction.listPersonByKey(function(json){
  141. // debugger;
  142. this.userListSearchAreaNode.getFirst().empty();
  143. this.userListSearchAreaNode.getLast().empty();
  144. json.data.each(function(user){
  145. if (layout.desktop.session.user.name!=user) new MWF.xDesktop.UserPanel.User(this.userListSearchAreaNode, this, user.name);
  146. }.bind(this));
  147. }.bind(this), null, key);
  148. }
  149. },
  150. createUserList: function(){
  151. this.userListTitleNode = new Element("div", {"styles": this.css.userListTitleNode}).inject(this.userListNode);
  152. this.userListChatTab = new Element("div", {"styles": this.css.userListChatTab}).inject(this.userListTitleNode);
  153. this.userListOnlineTab = new Element("div", {"styles": this.css.userListOnlineTab}).inject(this.userListTitleNode);
  154. this.userListSearchTab = new Element("div", {"styles": this.css.userListSearchTab}).inject(this.userListTitleNode);
  155. // this.userListGroupTab = new Element("div", {"styles": this.css.userListChartTab}).inject(this.userListTitleNode);
  156. this.userListChatTab.addEvents({
  157. "mouseover": function(){if (this.currentList != this.userListChatTab) this.userListChatTab.setStyles(this.css.userListChatTab_over);}.bind(this),
  158. "mouseout": function(){ if (this.currentList != this.userListChatTab) this.userListChatTab.setStyles(this.css.userListChatTab); }.bind(this),
  159. "click": function(){this.loadChatList();}.bind(this)
  160. });
  161. this.userListOnlineTab.addEvents({
  162. "mouseover": function(){ if (this.currentList != this.userListOnlineTab) this.userListOnlineTab.setStyles(this.css.userListOnlineTab_over); }.bind(this),
  163. "mouseout": function(){ if (this.currentList != this.userListOnlineTab) this.userListOnlineTab.setStyles(this.css.userListOnlineTab); }.bind(this),
  164. "click": function(){this.loadOnlineList();}.bind(this)
  165. });
  166. this.userListSearchTab.addEvents({
  167. "mouseover": function(){ if (this.currentList != this.userListSearchTab) this.userListSearchTab.setStyles(this.css.userListSearchTab_over); }.bind(this),
  168. "mouseout": function(){ if (this.currentList != this.userListSearchTab) this.userListSearchTab.setStyles(this.css.userListSearchTab); }.bind(this),
  169. "click": function(){this.loadSearchList();}.bind(this)
  170. });
  171. this.currentList = this.userListOnlineTab;
  172. //MWF.UD.getData("chat", function(json) {
  173. // if (json.data) {
  174. // chartList = JSON.decode(json.data);
  175. // if (!chartList.users){
  176. // this.currentList = this.userListOnlineTab;
  177. // }else if (!chartList.users.length) this.currentList = this.userListOnlineTab;
  178. // }else{
  179. // this.currentList = this.userListOnlineTab;
  180. // }
  181. //}.bind(this));
  182. this.userListScrollNode = new Element("div", {"styles": this.css.userListScrollNode}).inject(this.userListNode);
  183. this.userListChatAreaNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListScrollNode);
  184. this.userListChatAreaOnlineNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListChatAreaNode);
  185. this.userListChatAreaOfflineNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListChatAreaNode);
  186. this.userListOnlineAreaNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListScrollNode);
  187. this.userListOnlineAreaOnlineNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListOnlineAreaNode);
  188. this.userListOnlineAreaOfflineNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListOnlineAreaNode);
  189. this.userListSearchAreaNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListScrollNode);
  190. this.userListSearchAreaOnlineNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListSearchAreaNode);
  191. this.userListSearchAreaOfflineNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListSearchAreaNode);
  192. this.loadChatOnlineList();
  193. MWF.require("MWF.widget.ScrollBar", function(){
  194. new MWF.widget.ScrollBar(this.userListScrollNode, {
  195. "style":"xDesktop_Message", "where": "before", "indent": false, "distance": 50, "friction": 6, "axis": {"x": false, "y": true}
  196. });
  197. }.bind(this));
  198. },
  199. loadChatOnlineList: function(){
  200. MWF.UD.getData("chat", function(json) {
  201. if (json.data) {
  202. this.chatData = JSON.decode(json.data);
  203. chatList = this.chatData.chatList;
  204. onlineList = this.chatData.onlineList;
  205. if (chatList){
  206. if (chatList.length){
  207. chatList.each(function(user){
  208. if (layout.desktop.session.user.name!=user) this.users["chat"+user] = new MWF.xDesktop.UserPanel.User(this.userListChatAreaNode, this, user);
  209. }.bind(this));
  210. }else{
  211. // this.setNoChatListText();
  212. }
  213. }else{
  214. // this.setNoChatListText();
  215. }
  216. if (onlineList){
  217. if (onlineList.length){
  218. onlineList.each(function(user){
  219. if (layout.desktop.session.user.name!=user) this.users["online"+user] = new MWF.xDesktop.UserPanel.User(this.userListOnlineAreaNode, this, user);
  220. }.bind(this));
  221. }else{
  222. // this.setNoOnlineListText();
  223. }
  224. }else{
  225. // this.setNoOnlineListText();
  226. }
  227. }
  228. if (!layout.desktop.socket) layout.desktop.openWebSocket();
  229. }.bind(this));
  230. },
  231. loadChatList: function(){
  232. // this.userListChatAreaNode.empty();
  233. this.userListChatAreaNode.setStyle("display", "block");
  234. this.userListOnlineAreaNode.setStyle("display", "none");
  235. this.userListSearchAreaNode.setStyle("display", "none");
  236. this.userListChatTab.setStyles(this.css.userListChatTab_current);
  237. this.userListOnlineTab.setStyles(this.css.userListOnlineTab);
  238. this.userListSearchTab.setStyles(this.css.userListSearchTab);
  239. this.currentList = this.userListChatTab;
  240. },
  241. loadOnlineList: function(){
  242. // this.userListOnlineAreaNode.empty();
  243. this.userListOnlineAreaNode.setStyle("display", "block");
  244. this.userListChatAreaNode.setStyle("display", "none");
  245. this.userListSearchAreaNode.setStyle("display", "none");
  246. this.userListOnlineTab.setStyles(this.css.userListOnlineTab_current);
  247. this.userListChatTab.setStyles(this.css.userListChatTab);
  248. this.userListSearchTab.setStyles(this.css.userListSearchTab);
  249. this.currentList = this.userListOnlineTab;
  250. //if (!this.onlineAction) this.onlineAction = new MWF.xDesktop.Actions.RestActions("/xDesktop/Actions/action.json", "x_collaboration_assemble_websocket");
  251. //this.onlineAction.invoke({"name": "listOnline", "success": function(json){
  252. // debugger;
  253. // if (json.data){
  254. // json.data.each(function(user){
  255. // if (layout.desktop.session.user.name!=user) this.users["online"+user] = new MWF.xDesktop.UserPanel.User(this.userListOnlineAreaNode, this, user);
  256. // }.bind(this));
  257. // }
  258. //}.bind(this)});
  259. },
  260. loadSearchList: function(){
  261. this.userListOnlineAreaNode.setStyle("display", "none");
  262. this.userListChatAreaNode.setStyle("display", "none");
  263. this.userListSearchAreaNode.setStyle("display", "block");
  264. this.userListOnlineTab.setStyles(this.css.userListOnlineTab);
  265. this.userListChatTab.setStyles(this.css.userListChatTab);
  266. this.userListSearchTab.setStyles(this.css.userListSearchTab_current);
  267. this.currentList = this.userListSearchTab;
  268. },
  269. listOnlineUser: function(){
  270. //MWF.xDesktop.Actions.RestActions
  271. },
  272. hide: function(){
  273. this.node.setStyle("display", "none");
  274. this.isShow = false;
  275. },
  276. show: function(){
  277. this.node.inject($(document.body));
  278. var zidx = MWF.xDesktop.zIndexPool.applyZindex();
  279. this.node.setStyles({
  280. "display": "block",
  281. "z-index": zidx
  282. });
  283. this.setPosition();
  284. this.currentList.click();
  285. this.isShow = true;
  286. if (layout.desktop.currentApp) layout.desktop.currentApp.setUncurrent();
  287. },
  288. setPosition: function(){
  289. var size = this.container.getSize();
  290. var position = this.container.getPosition(this.container.getOffsetParent());
  291. var y = size.y-24;
  292. var top = position.y+10;
  293. this.node.setStyle("height", ""+y+"px");
  294. this.node.setStyle("top", ""+top+"px");
  295. var titleSize = this.titleNode.getSize();
  296. var userInforSize = this.userInforNode.getSize();
  297. var userSearchSize = this.userSearchNode.getSize();
  298. var userMenuSize = this.userMenuNode.getSize();
  299. var height = y-(titleSize.y+userInforSize.y+userSearchSize.y+userMenuSize.y);
  300. this.userListNode.setStyle("height", ""+height+"px");
  301. var userListTitleSize = this.userListTitleNode.getSize();
  302. height = height-userListTitleSize.y;
  303. this.userListScrollNode.setStyle("height", ""+height+"px");
  304. },
  305. receiveChatMessage: function(data){
  306. var chat = this.desktop.apps["Chat"];
  307. if (chat){
  308. var key = data.fromPerson+layout.desktop.session.user.name;
  309. var dialogue = chat.dialogues[key];
  310. if (dialogue){
  311. dialogue.showMessage(data, data.fromPerson);
  312. if (chat.current != dialogue){
  313. layout.desktop.playMessageAudio();
  314. dialogue.addUnreadMessage(data);
  315. }
  316. if (layout.desktop.currentApp!=chat){
  317. var userItem = this.users["online"+data.fromPerson];
  318. this.sendTooltipMessage(data, userItem)
  319. layout.desktop.playMessageAudio();
  320. }
  321. //window.focus();
  322. }else{
  323. this.receiveMessageRecodePanel(data);
  324. }
  325. }else{
  326. this.receiveMessageRecodePanel(data);
  327. }
  328. },
  329. receiveMessageRecodePanel: function(data){
  330. var userItem = this.users["online"+data.fromPerson];
  331. if (userItem){
  332. userItem.addUnreadMessage(data);
  333. }else{
  334. this.users["online"+data.fromPerson] = new MWF.xDesktop.UserPanel.User(this.userListOnlineAreaNode, this, data.fromPerson);
  335. userItem = this.users["online"+data.fromPerson];
  336. userItem.addUnreadMessage(data);
  337. }
  338. this.sendTooltipMessage(data, userItem);
  339. layout.desktop.playMessageAudio();
  340. },
  341. sendTooltipMessage: function(data, userItem){
  342. var content = "<div style=\"height: 20px; line-height: 20px\">"+data.text+"</div></div>"
  343. msg = {
  344. "subject": data.fromPerson+" "+MWF.LP.desktop.say+": ",
  345. "content": content
  346. };
  347. var tooltipItem = layout.desktop.message.addTooltip(msg);
  348. tooltipItem.contentNode.addEvent("click", function(){
  349. userItem.openChat();
  350. });
  351. }
  352. });
  353. MWF.xDesktop.UserPanel.User = new Class({
  354. initialize: function(container, panel, name){
  355. this.panel = panel;
  356. this.name = name;
  357. this.data = null;
  358. this.container = container;
  359. this.onlineContainer = container.getFirst();
  360. this.offlineContainer = container.getLast();
  361. this.css = this.panel.css;
  362. this.checkOnlineTime = new Date();
  363. this.unreadDatas = [];
  364. this.load();
  365. },
  366. createNode: function(){
  367. this.node = new Element("div", {"styles": this.css.chatUserNode}).inject(this.onlineContainer);
  368. this.userIconAreaNode = new Element("div", {"styles": this.css.userListIconAreaNode}).inject(this.node);
  369. this.userIconNode = new Element("img", {"styles": this.css.userListIconNode}).inject(this.userIconAreaNode);
  370. this.userTextInforNode = new Element("div", {"styles": this.css.userListTextInforNode}).inject(this.node);
  371. this.userNameInforNode = new Element("div", {"styles": this.css.userListNameInforNode}).inject(this.userTextInforNode);
  372. this.userNameTextInforNode = new Element("div", {"styles": this.css.userListNameTextInforNode}).inject(this.userNameInforNode);
  373. this.userListGenderFlagNode = new Element("div", {"styles": this.css.userListGenderFlagNode}).inject(this.userNameInforNode);
  374. this.userDutyTextInforNode = new Element("div", {"styles": this.css.userListDutyTextInforNode}).inject(this.userNameInforNode);
  375. this.userSignInforNode = new Element("div", {"styles": this.css.userListSignInforNode}).inject(this.userTextInforNode);
  376. },
  377. checkOnline: function(){
  378. if (this.data.status=="offline"){
  379. this.userIconNode.set("src", MWF.grayscale(this.userIconNode.get("src")));
  380. this.node.inject(this.offlineContainer);
  381. }
  382. },
  383. loadPerson: function(){
  384. this.panel.userAction.getPersonComplex(function(json){
  385. this.data = json.data;
  386. if (json.data.icon){
  387. this.userIconNode.set("src", "data:image/png;base64,"+json.data.icon+"");
  388. }else{
  389. if (json.data.genderType=="f"){
  390. this.userIconNode.set("src", ""+MWF.defaultPath+"/xDesktop/$UserPanel/default/icon/female.png");
  391. }else{
  392. this.userIconNode.set("src", ""+MWF.defaultPath+"/xDesktop/$UserPanel/default/icon/man.png");
  393. }
  394. }
  395. if (json.data.status=="offline"){
  396. this.userIconNode.set("src", MWF.grayscale(this.userIconNode.get("src")));
  397. }
  398. this.userNameTextInforNode.set("text", json.data.display);
  399. if (json.data.genderType=="f"){
  400. this.userListGenderFlagNode.setStyle("background-image", "url("+MWF.defaultPath+"/xDesktop/$UserPanel/default/icon/female_flag.png)");
  401. }else{
  402. this.userListGenderFlagNode.setStyle("background-image", "url("+MWF.defaultPath+"/xDesktop/$UserPanel/default/icon/male_flag.png)");
  403. }
  404. var departments = [];
  405. json.data.identityList.each(function(id){
  406. departments.push(id.department);
  407. }.bind(this));
  408. var dutys = [];
  409. //json.data.companyDutyList.each(function(duty){
  410. // dutys.push(duty.name);
  411. //}.bind(this));
  412. //json.data.departmentDutyList.each(function(duty){
  413. // dutys.push(duty.name);
  414. //}.bind(this));
  415. var text = (dutys.length) ? departments.join(", ")+ "["+ dutys.join(", ")+"]" : departments.join(", ");
  416. this.userDutyTextInforNode.set("text", text);
  417. this.userSignInforNode.set("text", json.data.signature || MWF.LP.desktop.nosign);
  418. this.checkOnline();
  419. this.createPersonInforNode();
  420. }.bind(this), null, this.name);
  421. },
  422. createPersonInforNode: function(){
  423. var dutys = [];
  424. this.data.companyDutyList.each(function(duty){
  425. dutys.push(duty.name);
  426. }.bind(this));
  427. this.data.departmentDutyList.each(function(duty){
  428. dutys.push(duty.name);
  429. }.bind(this));
  430. this.personInforNode = new Element("div", {"styles": this.css.personInforNode});
  431. var html = "<table width=\"100%\" cellpadding=\"3px\" border=\"0\">";
  432. html += "<tr><td>"+MWF.LP.desktop.person.personEmployee+"</td><td>"+this.data.employee+"</td></tr>";
  433. html += "<tr><td>"+MWF.LP.desktop.person.personMobile+"</td><td>"+this.data.mobile+"</td></tr>";
  434. html += "<tr><td>"+MWF.LP.desktop.person.personMail+"</td><td>"+this.data.mail+"</td></tr>"
  435. html += "<tr><td>"+MWF.LP.desktop.person.personQQ+"</td><td>"+this.data.qq+"</td></tr>";
  436. html += "<tr><td>"+MWF.LP.desktop.person.personWeixin+"</td><td>"+this.data.weixin+"</td></tr>";
  437. if (dutys.length) html += "<tr><td>"+MWF.LP.desktop.person.duty+"</td><td>"+dutys.join(", ")+"</td></tr>";
  438. html += "</table>";
  439. this.personInforNode.set("html", html);
  440. },
  441. load: function(){
  442. this.createNode();
  443. this.loadPerson();
  444. this.setEvent();
  445. },
  446. setEvent: function(){
  447. this.node.addEvents({
  448. "mouseover": function(){ this.node.setStyles(this.css.chatUserNode_over); }.bind(this),
  449. "mouseout": function(){ this.node.setStyles(this.css.chatUserNode); }.bind(this),
  450. "dblclick": function(e){this.openChat(e);}.bind(this),
  451. "click": function(e){this.openChat(e);}.bind(this)
  452. });
  453. this.userIconAreaNode.addEvents({
  454. "mouseover": function(){ this.showPersonInfor(); }.bind(this),
  455. "mouseout": function(){ this.hidePersonInfor(); }.bind(this)
  456. });
  457. },
  458. showPersonInfor: function(){
  459. this.personInforNode.inject(this.container);
  460. this.personInforNode.setStyle("display", "block");
  461. var size = this.personInforNode.getSize();
  462. var position = this.node.getPosition(this.node.getOffsetParent());
  463. var panelSize = this.panel.node.getSize();
  464. var top = position.y;
  465. var right = panelSize.x+5;
  466. this.personInforNode.setStyles({
  467. "top": ""+top+"px",
  468. "right": ""+right+"px"
  469. });
  470. },
  471. hidePersonInfor: function(){
  472. this.personInforNode.setStyle("display", "none");
  473. },
  474. destroy: function(){
  475. this.node.destroy();
  476. delete this.panel.users["online"+this.name];
  477. MWF.release(this);
  478. delete this;
  479. },
  480. openChat: function(e){
  481. var chat = layout.desktop.apps["Chat"];
  482. if (chat){
  483. var key = this.name+layout.desktop.session.user.name;
  484. var dialogue = chat.dialogues[key];
  485. if (!dialogue) dialogue = chat.addDialogue(this.panel.owner, [this.data]);
  486. this.unreadDatas.each(function(data){
  487. dialogue.showMessage(data, data.fromPerson);
  488. });
  489. dialogue.setCurrent();
  490. this.clearUnread();
  491. }
  492. var _self = this;
  493. layout.desktop.openApplication(e, "Chat", {
  494. "onPostLoad": function(){
  495. dialogue = this.addDialogue(_self.panel.owner, [_self.data]);
  496. _self.unreadDatas.each(function(data){
  497. dialogue.showMessage(data, data.fromPerson);
  498. });
  499. _self.clearUnread();
  500. }
  501. });
  502. },
  503. addUnreadMessage: function(data){
  504. if (!this.unreadNode) this.createUnreadnode();
  505. this.unreadDatas.push(data);
  506. if (this.unreadDatas.length>100) this.unreadDatas.shift();
  507. this.unreadNode.set("text", this.unreadDatas.length);
  508. this.node.inject(this.container, "top");
  509. },
  510. createUnreadnode: function(){
  511. this.unreadNode = new Element("div", {"styles": this.css.userListUnreadNode}).inject(this.node, "bottom");
  512. },
  513. clearUnread: function(){
  514. if (this.unreadNode){
  515. this.unreadDatas = null;
  516. this.unreadDatas = [];
  517. this.unreadNode.destroy();
  518. this.unreadNode = null;
  519. }
  520. }
  521. });