Main.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. MWF.xApplication.IM.options.multitask = false;
  2. MWF.require("MWF.widget.Tree", null, false);
  3. MWF.xDesktop.requireApp("IM", "Actions.RestActions", null, false);
  4. MWF.xApplication.IM.Main = new Class({
  5. Extends: MWF.xApplication.Common.Main,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "name": "IM",
  10. "icon": "icon.png",
  11. "title": MWF.xApplication.IM.LP.title
  12. },
  13. onQueryLoad: function(){
  14. this.lp = MWF.xApplication.IM.LP;
  15. this.left = null;
  16. this.top = null;
  17. this.height = null;
  18. this.userAction = MWF.Actions.get("x_organization_assemble_control");
  19. this.socketAction = MWF.Actions.get("x_collaboration_assemble_websocket");
  20. //if (!this.userAction) this.userAction = new MWF.xApplication.IM.Actions.RestActions();
  21. },
  22. loadWindow: function(isCurrent){
  23. this.fireAppEvent("queryLoadWindow");
  24. this.window = new MWF.xDesktop.WindowTransparent(this);
  25. this.fireAppEvent("loadWindow");
  26. this.window.show();
  27. this.content = this.window.content;
  28. if (isCurrent) this.setCurrent();
  29. this.fireAppEvent("postLoadWindow");
  30. this.fireAppEvent("queryLoadApplication");
  31. this.loadApplication(function(){
  32. this.fireAppEvent("postLoadApplication");
  33. }.bind(this));
  34. },
  35. loadApplication: function(callback){
  36. this.node = new Element("div#IM", {"styles": this.css.panelNode}).inject(this.content);
  37. this.titleNode = new Element("div", {"styles": this.css.titleNode}).inject(this.node);
  38. this.userInforNode = new Element("div", {"styles": this.css.userInforNode}).inject(this.node);
  39. this.userSearchNode = new Element("div", {"styles": this.css.userSearchNode}).inject(this.node);
  40. this.userListNode = new Element("div", {"styles": this.css.userListNode}).inject(this.node);
  41. this.userMenuNode = new Element("div", {"styles": this.css.userMenuNode}).inject(this.node);
  42. this.createTitle();
  43. this.createUserInfor();
  44. this.createSearch();
  45. this.createUserList();
  46. this.setResizeEvent();
  47. this.checkPersonOnline();
  48. this.addEvent("queryClose", function(){
  49. if (this.checkPersonOnlineTimerID) window.clearInterval(this.checkPersonOnlineTimerID);
  50. }.bind(this));
  51. //this.createBottomMenu();
  52. },
  53. checkPersonOnline: function(){
  54. this.checkPersonOnlineTimerID = window.setInterval(function(){
  55. if (this.onlineList) this.checkOnline(this.onlineList.personList);
  56. if (this.searchList) this.checkOnline(this.searchList.personList);
  57. if (this.chatList) this.checkOnline(this.chatList.personList);
  58. }.bind(this), 20000);
  59. },
  60. checkOnline: function(personList){
  61. Object.each(personList, function(v, k){
  62. this.socketAction.personOnline(v.data.distinguishedName, function(json){
  63. if (json.data.onlineStatus == "online"){
  64. v.online();
  65. }else{
  66. v.offline();
  67. }
  68. }.bind(this));
  69. }.bind(this));
  70. },
  71. setNodePosition: function(){
  72. if (this.top) this.node.setStyle("top", ""+this.top+"px");
  73. if (this.left) this.node.setStyle("left", ""+this.top+"px");
  74. if (this.height) this.node.setStyle("height", ""+this.top+"px");
  75. },
  76. setResizeEvent: function(){
  77. this.setNodePositionAndSizeFun = this.setNodePositionAndSize.bind(this);
  78. this.setNodePositionAndSizeFun();
  79. this.addEvent("current", this.setNodePositionAndSizeFun);
  80. this.desktop.addEvent("resize", this.setNodePositionAndSizeFun);
  81. this.addEvent("postClose", function(){
  82. if (this.desktop) this.desktop.removeEvent("resize", this.setNodePositionAndSizeFun);
  83. }.bind(this));
  84. },
  85. setNodePositionAndSize: function(){
  86. this.setNodePosition();
  87. var size = this.desktop.desktopNode.getSize();
  88. var position = this.desktop.desktopNode.getPosition();
  89. var nodeSize = this.node.getSize();
  90. if (!this.left || (this.left>(size.x-nodeSize.x-10)) || this.left<0){
  91. var left = size.x-nodeSize.x-10;
  92. if (left<0) left = 0;
  93. this.node.setStyle("left", ""+left+"px");
  94. }
  95. if (!this.top || this.top<(position.y+10)){
  96. var top = position.y+10;
  97. this.node.setStyle("top", ""+top+"px");
  98. }
  99. if (!this.height || this.height>(size.y-24)){
  100. var height = size.y-24;
  101. this.node.setStyle("height", ""+height+"px");
  102. }
  103. this.setNodeSize();
  104. },
  105. setNodeSize: function(){
  106. var size = this.node.getSize();
  107. var titleSize = this.titleNode.getSize();
  108. var userInforSize = this.userInforNode.getSize();
  109. var userSearchSize = this.userSearchNode.getSize();
  110. var userMenuSize = this.userMenuNode.getSize();
  111. var height = size.y-(titleSize.y+userInforSize.y+userSearchSize.y+userMenuSize.y);
  112. this.userListNode.setStyle("height", ""+height+"px");
  113. var userListTitleSize = this.userListTitleNode.getSize();
  114. height = height-userListTitleSize.y;
  115. this.userListScrollNode.setStyle("height", ""+height+"px");
  116. },
  117. createTitle: function(){
  118. this.closeAction = new Element("div", {"styles": this.css.closeActionNode}).inject(this.titleNode);
  119. this.closeAction.addEvent("click", function(e){
  120. this.close();
  121. e.stopPropagation();
  122. }.bind(this));
  123. var drag = new Drag.Move(this.node, {
  124. "handle": this.titleNode,
  125. "container": this.desktop.desktopNode,
  126. "onDrop": function(){
  127. var p = this.node.getPosition();
  128. this.left = p.x;
  129. this.top = p.y;
  130. }.bind(this)
  131. });
  132. },
  133. createUserInfor: function(){
  134. this.userIconAreaNode = new Element("div", {"styles": this.css.userIconAreaNode}).inject(this.userInforNode);
  135. this.userIconNode = new Element("img", {"styles": this.css.userIconNode}).inject(this.userIconAreaNode);
  136. this.userTextInforNode = new Element("div", {"styles": this.css.userTextInforNode}).inject(this.userInforNode);
  137. this.userNameInforNode = new Element("div", {"styles": this.css.userNameInforNode}).inject(this.userTextInforNode);
  138. this.userNameTextInforNode = new Element("div", {"styles": this.css.userNameTextInforNode}).inject(this.userNameInforNode);
  139. this.userDutyTextInforNode = new Element("div", {"styles": this.css.userDutyTextInforNode}).inject(this.userNameInforNode);
  140. this.userSignInforNode = new Element("div", {"styles": this.css.userSignInforNode}).inject(this.userTextInforNode);
  141. this.userAction.getPerson(layout.desktop.session.user.id, function(json){
  142. if (!json.data) json.data = {"name": layout.desktop.session.user.name, "distinguishedName": layout.desktop.session.user.distinguishedName, "woIdentityList": []};
  143. this.owner = json.data;
  144. this.userIconNode.set("src", this.userAction.getPersonIcon(json.data.id));
  145. this.userNameTextInforNode.set("text", json.data.name);
  146. var units = [];
  147. if (json.data.woIdentityList){
  148. json.data.woIdentityList.each(function(id){
  149. units.push(id.unitName);
  150. }.bind(this));
  151. }
  152. var text = units.join(", ");
  153. this.userDutyTextInforNode.set("text", text);
  154. this.userSignInforNode.set("text", json.data.signature || MWF.LP.desktop.nosign);
  155. }.bind(this));
  156. },
  157. createSearch: function(){
  158. this.searchInput = new Element("input", {
  159. "styles": this.css.searchInput,
  160. "type": "text",
  161. "value": MWF.LP.desktop.searchUser
  162. }).inject(this.userSearchNode);
  163. this.searchInput.addEvents({
  164. "focus": function(){ if (this.searchInput.get("value")==MWF.LP.desktop.searchUser) this.searchInput.set("value", "");}.bind(this),
  165. "blur": function(){ if (!this.searchInput.get("value")) this.searchInput.set("value", MWF.LP.desktop.searchUser);}.bind(this),
  166. "keydown": function(e){ if (e.code==13) this.doSearch(); }.bind(this)
  167. });
  168. },
  169. doSearch: function(){
  170. var key = this.searchInput.get("value");
  171. if (key){
  172. this.userListSearchTab.click();
  173. this.userAction.listPersonByKey(function(json){
  174. if (this.searchList) this.searchList.empty();
  175. json.data.each(function(user){
  176. if (user.distinguishedName!==layout.desktop.session.user.distinguishedName){
  177. this.socketAction.personOnline(user.distinguishedName, function(ojson){
  178. if (ojson.data.onlineStatus === "online"){
  179. this.searchList.appendIdentityTreeNode(user, this.searchList.onlineTree);
  180. }else{
  181. this.searchList.appendIdentityTreeNode(user, this.searchList.offlineTree);
  182. }
  183. }.bind(this));
  184. }
  185. }.bind(this));
  186. }.bind(this), null, key);
  187. }
  188. },
  189. createUserList: function(){
  190. this.userListTitleNode = new Element("div", {"styles": this.css.userListTitleNode}).inject(this.userListNode);
  191. this.userListChatTab = new Element("div", {"styles": this.css.userListChatTab}).inject(this.userListTitleNode);
  192. this.userListOnlineTab = new Element("div", {"styles": this.css.userListOnlineTab}).inject(this.userListTitleNode);
  193. this.userListSearchTab = new Element("div", {"styles": this.css.userListSearchTab}).inject(this.userListTitleNode);
  194. // this.userListGroupTab = new Element("div", {"styles": this.css.userListChartTab}).inject(this.userListTitleNode);
  195. this.userListChatTab.addEvents({
  196. "mouseover": function(){if (this.currentList != this.userListChatTab) this.userListChatTab.setStyles(this.css.userListChatTab_over);}.bind(this),
  197. "mouseout": function(){ if (this.currentList != this.userListChatTab) this.userListChatTab.setStyles(this.css.userListChatTab); }.bind(this),
  198. "click": function(){this.loadChatList();}.bind(this)
  199. });
  200. this.userListOnlineTab.addEvents({
  201. "mouseover": function(){ if (this.currentList != this.userListOnlineTab) this.userListOnlineTab.setStyles(this.css.userListOnlineTab_over); }.bind(this),
  202. "mouseout": function(){ if (this.currentList != this.userListOnlineTab) this.userListOnlineTab.setStyles(this.css.userListOnlineTab); }.bind(this),
  203. "click": function(){this.loadOnlineList();}.bind(this)
  204. });
  205. this.userListSearchTab.addEvents({
  206. "mouseover": function(){ if (this.currentList != this.userListSearchTab) this.userListSearchTab.setStyles(this.css.userListSearchTab_over); }.bind(this),
  207. "mouseout": function(){ if (this.currentList != this.userListSearchTab) this.userListSearchTab.setStyles(this.css.userListSearchTab); }.bind(this),
  208. "click": function(){this.loadSearchList();}.bind(this)
  209. });
  210. this.currentList = this.userListOnlineTab;
  211. this.userListScrollNode = new Element("div", {"styles": this.css.userListScrollNode}).inject(this.userListNode);
  212. this.userListChatAreaNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListScrollNode);
  213. this.userListChatAreaOnlineNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListChatAreaNode);
  214. this.userListChatAreaOfflineNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListChatAreaNode);
  215. this.userListOnlineAreaNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListScrollNode);
  216. this.userListOnlineAreaTreeNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListOnlineAreaNode);
  217. this.userListSearchAreaNode = new Element("div", {"styles": this.css.userListAreaNode}).inject(this.userListScrollNode);
  218. this.userListSearchAreaOnlineNode = new Element("div#online", {"styles": this.css.userListAreaNode}).inject(this.userListSearchAreaNode);
  219. this.userListSearchAreaOfflineNode = new Element("div#offline", {"styles": this.css.userListAreaNode}).inject(this.userListSearchAreaNode);
  220. MWF.require("MWF.widget.ScrollBar", function(){
  221. new MWF.widget.ScrollBar(this.userListScrollNode, {
  222. "style":"xDesktop_Message", "where": "before", "indent": false, "distance": 50, "friction": 6, "axis": {"x": false, "y": true}
  223. });
  224. }.bind(this));
  225. //this.loadChatOnlineList();
  226. this.loadOnlineList();
  227. },
  228. loadChatList: function(){
  229. this.userListOnlineAreaNode.setStyle("display", "none");
  230. this.userListChatAreaNode.setStyle("display", "block");
  231. this.userListSearchAreaNode.setStyle("display", "none");
  232. this.userListChatAreaOnlineNode.setStyle("display", "block");
  233. this.userListChatAreaOfflineNode.setStyle("display", "block");
  234. this.userListOnlineTab.setStyles(this.css.userListOnlineTab);
  235. this.userListChatTab.setStyles(this.css.userListChatTab_current);
  236. this.userListSearchTab.setStyles(this.css.userListSearchTab);
  237. this.currentList = this.userListChatTab;
  238. if (!this.chatList){
  239. this.chatList = new MWF.xApplication.IM.ChatList(this);
  240. }
  241. },
  242. loadOnlineList: function(){
  243. this.userListOnlineAreaNode.setStyle("display", "block");
  244. this.userListChatAreaNode.setStyle("display", "none");
  245. this.userListSearchAreaNode.setStyle("display", "none");
  246. this.userListOnlineAreaTreeNode.setStyle("display", "block");
  247. this.userListOnlineTab.setStyles(this.css.userListOnlineTab_current);
  248. this.userListChatTab.setStyles(this.css.userListChatTab);
  249. this.userListSearchTab.setStyles(this.css.userListSearchTab);
  250. this.currentList = this.userListOnlineTab;
  251. if (!this.onlineList){
  252. this.onlineList = new MWF.xApplication.IM.OnlineList(this);
  253. }
  254. },
  255. loadSearchList: function(){
  256. this.userListOnlineAreaNode.setStyle("display", "none");
  257. this.userListChatAreaNode.setStyle("display", "none");
  258. this.userListSearchAreaNode.setStyle("display", "block");
  259. this.userListSearchAreaOnlineNode.setStyle("display", "block");
  260. this.userListSearchAreaOfflineNode.setStyle("display", "block");
  261. this.userListOnlineTab.setStyles(this.css.userListOnlineTab);
  262. this.userListChatTab.setStyles(this.css.userListChatTab);
  263. this.userListSearchTab.setStyles(this.css.userListSearchTab_current);
  264. this.currentList = this.userListSearchTab;
  265. if (!this.searchList){
  266. this.searchList = new MWF.xApplication.IM.SearchList(this);
  267. }
  268. },
  269. checkUnread: function(from){
  270. var person = null;
  271. if (this.onlineList){
  272. person = this.onlineList.personList[from];
  273. if (person) person.checkUnread();
  274. }
  275. person = null;
  276. if (this.searchList){
  277. person = this.searchList.personList[from];
  278. if (person) person.checkUnread();
  279. }
  280. person = null;
  281. if (this.chatList){
  282. person = this.chatList.personList[from];
  283. if (person) person.checkUnread();
  284. }
  285. }
  286. });
  287. MWF.xApplication.IM.OnlineList = new Class({
  288. initialize: function(app){
  289. this.app = app;
  290. this.userAction = this.app.userAction;
  291. this.socketAction = this.app.socketAction;
  292. this.css = this.app.css;
  293. this.container = this.app.userListOnlineAreaNode;
  294. this.personList = {};
  295. this.load();
  296. },
  297. load: function(){
  298. this.tree = new MWF.widget.Tree(this.container, {"style": "chat"});
  299. this.tree.addEvent("queryExpand", function(item){
  300. this.expandItem(item);
  301. }.bind(this));
  302. this.tree.load();
  303. this.userAction.listTopUnit(function(json){
  304. json.data.each(function(data){
  305. var topItem = this.appendUnitItem(data, this.tree);
  306. topItem.expandOrCollapse();
  307. }.bind(this));
  308. }.bind(this));
  309. },
  310. appendUnitItem: function(data, item){
  311. var obj = {
  312. "expand": false,
  313. "title": data.name,
  314. "text": data.name,
  315. "action": function(item){item.expandOrCollapse();}.bind(this),
  316. "icon": "companyicon.png",
  317. "style": "company"
  318. };
  319. var subitem = item.appendChild(obj);
  320. subitem.data = data;
  321. //subitem.itemType = "company";
  322. if (data.subDirectUnitCount || data.subDirectIdentityCount) this.appendLoaddingItem(subitem);
  323. return subitem;
  324. },
  325. // appendDepartmentItem: function(data, item){
  326. // var obj = {
  327. // "expand": false,
  328. // "title": data.display,
  329. // "text": data.display,
  330. // "action": function(item){item.expandOrCollapse();}.bind(this),
  331. // "icon": "departmenticon.png",
  332. // "style": "company"
  333. // };
  334. // var subitem = item.appendChild(obj);
  335. // subitem.data = data;
  336. // subitem.itemType = "department";
  337. // if (data.departmentSubDirectCount || data.companySubDirectCount || data.identitySubDirectCount) this.appendLoaddingItem(subitem);
  338. // return subitem;
  339. // },
  340. appendIdentityItem: function(data, item){
  341. this.appendIdentityTreeNode(data.woPerson, item);
  342. // this.userAction.getPersonComplex(function(json){
  343. //
  344. // }.bind(this), null, data.person);
  345. },
  346. appendIdentityTreeNode: function(data, item){
  347. var person = new MWF.xApplication.IM.Person(data, item, this);
  348. //this.personList[data.id] = person;
  349. this.personList[data.distinguishedName] = person;
  350. },
  351. expandItem: function(item){
  352. var sub = item.firstChild;
  353. if (sub && sub.options.text==="loadding..."){
  354. // var method = "";
  355. // if (item.itemType=="company") method = "listCompanySub";
  356. // if (item.itemType=="department") method = "listDepartmentSub";
  357. //if (method){
  358. sub.destroy();
  359. if (item.data.subDirectUnitCount){
  360. this.userAction.listSubUnitDirect(item.data.id, function(json){
  361. json.data.each(function(data){
  362. this.appendUnitItem(data, item);
  363. }.bind(this));
  364. }.bind(this));
  365. }
  366. if (item.data.subDirectIdentityCount){
  367. this.userAction.getUnit(item.data.id, function(json){
  368. json.data.woSubDirectIdentityList.each(function(data){
  369. this.appendIdentityItem(data, item);
  370. }.bind(this));
  371. }.bind(this));
  372. }
  373. }
  374. },
  375. appendLoaddingItem: function(item){
  376. item.appendChild({ "expand": false,"title": "loadding...","text": "loadding...","icon": ""});
  377. }
  378. });
  379. MWF.xApplication.IM.ChatList = new Class({
  380. Extends: MWF.xApplication.IM.OnlineList,
  381. load: function(){
  382. this.onlineTree = new MWF.widget.Tree(this.app.userListChatAreaOnlineNode, {"style": "chat"});
  383. this.onlineTree.load();
  384. this.offlineTree = new MWF.widget.Tree(this.app.userListChatAreaOfflineNode, {"style": "chat"});
  385. this.offlineTree.load();
  386. this.socketAction.listChat(function(json){
  387. json.data.each(function(data){
  388. var pName = (data.from===this.app.owner.distinguishedName) ? data.person : data.from;
  389. if (pName!==this.app.owner.distinguishedName){
  390. this.userAction.getPerson(pName, function(pjson){
  391. this.socketAction.personOnline(pjson.data.distinguishedName, function(ojson){
  392. if (ojson.data.onlineStatus === "online"){
  393. this.appendIdentityTreeNode(pjson.data, this.onlineTree);
  394. }else{
  395. this.appendIdentityTreeNode(pjson.data, this.offlineTree);
  396. }
  397. }.bind(this));
  398. }.bind(this));
  399. }
  400. }.bind(this));
  401. }.bind(this));
  402. }
  403. });
  404. MWF.xApplication.IM.SearchList = new Class({
  405. Extends: MWF.xApplication.IM.OnlineList,
  406. load: function(){
  407. this.onlineTree = new MWF.widget.Tree(this.app.userListSearchAreaOnlineNode, {"style": "chat"});
  408. this.onlineTree.load();
  409. this.offlineTree = new MWF.widget.Tree(this.app.userListSearchAreaOfflineNode, {"style": "chat"});
  410. this.offlineTree.load();
  411. },
  412. empty: function(){
  413. this.onlineTree.empty();
  414. this.offlineTree.empty();
  415. this.personList = null;
  416. this.personList = {};
  417. }
  418. });
  419. MWF.xApplication.IM.Person = new Class({
  420. initialize: function(data, parent, list){
  421. this.list = list;
  422. this.app = this.list.app;
  423. this.css = this.app.css;
  424. this.parent = parent;
  425. this.data = data;
  426. //this.onlineStatus = "offline";
  427. if (!this.data.hasOwnProperty("onlineStatus")){
  428. this.app.socketAction.personOnline(this.data.distinguishedName, function(json){
  429. this.data.onlineStatus = json.data.onlineStatus;
  430. this.load();
  431. }.bind(this));
  432. }else{
  433. this.load();
  434. }
  435. },
  436. load: function(){
  437. this.treeItem = this.parent.appendChild(this.getTreenodeObj());
  438. this.setOnlineFlag();
  439. this.createPersonInforNode();
  440. this.setEvent();
  441. this.checkUnread();
  442. //if (this.img.status==="error"){
  443. window.setTimeout(this.checkOnline.bind(this), 10000);
  444. //}
  445. },
  446. setEvent: function(){
  447. var _self = this;
  448. this.treeItem.itemNode.addEvents({
  449. "mouseover": function(){ this.setStyles(_self.css.chatUserNode_over); },
  450. "mouseout": function(){ this.setStyles(_self.css.chatUserNode); },
  451. "dblclick": function(e){_self.openChat(e);},
  452. "click": function(e){_self.openChat(e);}
  453. });
  454. this.treeItem.textNode.getElement("img").addEvents({
  455. "mouseover": function(){ _self.showPersonInfor(this); },
  456. "mouseout": function(){ _self.hidePersonInfor(this); }
  457. });
  458. },
  459. getImg: function(status, callback){
  460. var src = this.app.userAction.getPersonIcon(this.data.id);
  461. return {"status": "success", "src": src};
  462. },
  463. getTreenodeObj: function(callback){
  464. this.img = this.getImg();
  465. var html = "<div style='height: 56px; width: 56px; float: left'>"+"<img style='width:48px; height: 48px; margin:4px;' src='"+this.img.src+"' />"+"</div>" +
  466. "<div style='height: 56px; margin-left: 56px;'>" +
  467. "<div style='height: 30px; line-height: 36px; color: #666666'>"+this.data.name+"</div>" +
  468. "<div style='height: 26px; line-height: 22px; color: #999999'>"+(this.data.signature || this.app.lp.nosign)+"</div></div>";
  469. return {
  470. "expand": false,
  471. "title": this.data.name,
  472. "text": html,
  473. "action": "",
  474. "icon": "",
  475. "style": "person"
  476. };
  477. },
  478. createPersonInforNode: function(){
  479. this.app.userAction.getPerson(this.data.id, function(json){
  480. var dutys = [];
  481. json.data.woIdentityList.each(function(id){
  482. id.woUnitDutyList.each(function(duty){
  483. dutys.push(duty.woUnit.name+"["+duty.name+"]");
  484. }.bind(this));
  485. }.bind(this));
  486. this.personInforNode = new Element("div", {"styles": this.css.personInforNode});
  487. var html = "<table width=\"100%\" cellpadding=\"3px\" border=\"0\">";
  488. html += "<tr><td>"+MWF.LP.desktop.person.personEmployee+"</td><td>"+this.data.employee+"</td></tr>";
  489. html += "<tr><td>"+MWF.LP.desktop.person.personMobile+"</td><td>"+this.data.mobile+"</td></tr>";
  490. html += "<tr><td>"+MWF.LP.desktop.person.personMail+"</td><td>"+this.data.mail+"</td></tr>"
  491. html += "<tr><td>"+MWF.LP.desktop.person.personQQ+"</td><td>"+this.data.qq+"</td></tr>";
  492. html += "<tr><td>"+MWF.LP.desktop.person.personWeixin+"</td><td>"+this.data.weixin+"</td></tr>";
  493. if (dutys.length) html += "<tr><td>"+MWF.LP.desktop.person.duty+"</td><td>"+dutys.join(", ")+"</td></tr>";
  494. html += "</table>";
  495. this.personInforNode.set("html", html);
  496. }.bind(this));
  497. // var dutys = [];
  498. // this.data.identityList.each(function(i){
  499. // i.companyDutyList.each(function(duty){
  500. // dutys.push(i.companyDutyList+"["+duty.name+"]");
  501. // }.bind(this));
  502. // i.departmentDutyList.each(function(duty){
  503. // dutys.push(i.departmentName+"["+duty.name+"]");
  504. // }.bind(this));
  505. // }.bind(this));
  506. },
  507. showPersonInfor: function(node){
  508. this.personInforNode.inject(this.app.content);
  509. this.personInforNode.setStyle("display", "block");
  510. var size = this.personInforNode.getSize();
  511. var position = node.getPosition(this.app.content);
  512. var p = this.treeItem.tree.container.getPosition(this.app.content);
  513. var top = position.y;
  514. var left = p.x - size.x-5;
  515. this.personInforNode.setStyles({
  516. "top": ""+top+"px",
  517. "left": ""+left+"px"
  518. });
  519. },
  520. hidePersonInfor: function(){
  521. this.personInforNode.setStyle("display", "none");
  522. },
  523. checkUnread: function(){
  524. if (layout.desktop.widgets["IMIMWidget"]){
  525. var unShowMessage = layout.desktop.widgets["IMIMWidget"].unShowMessage;
  526. var key = this.data.distinguishedName+this.app.owner.distinguishedName;
  527. if (unShowMessage[key]){
  528. var count = unShowMessage[key].length;
  529. if (count){
  530. this.setUnread(count);
  531. }else{
  532. this.clearUnread();
  533. }
  534. }else{
  535. this.clearUnread();
  536. }
  537. //layout.desktop.widgets["IMIMWidget"].setUnread();
  538. }
  539. },
  540. setUnread: function(count){
  541. if (!this.unreadNode){
  542. this.unreadNode = new Element("div", {"styles": this.css.userListUnreadNode}).inject(this.treeItem.textNode);
  543. }
  544. this.unreadNode.set("text", count);
  545. },
  546. clearUnread: function(){
  547. if (this.unreadNode){
  548. this.unreadNode.destroy();
  549. this.unreadNode = null;
  550. delete this.unreadNode;
  551. }
  552. },
  553. openChat: function(e){
  554. if (this.data.distinguishedName!==this.app.owner.distinguishedName){
  555. var chat = layout.desktop.apps["Chat"];
  556. if (chat){
  557. var key = this.data.distinguishedName+layout.desktop.session.user.distinguishedName;
  558. var dialogue = chat.dialogues[key];
  559. if (!dialogue) dialogue = chat.addDialogue(this.app.owner, [this.data]);
  560. dialogue.setCurrent();
  561. }
  562. var _self = this;
  563. layout.desktop.openApplication(e, "Chat", {
  564. "onPostLoad": function(){
  565. dialogue = this.addDialogue(_self.app.owner, [_self.data]);
  566. }
  567. });
  568. }
  569. },
  570. checkOnline: function(){
  571. if (this.app){
  572. this.app.socketAction.personOnline(this.data.distinguishedName, function(json){
  573. if (json.data.onlineStatus === "online"){
  574. this.online();
  575. }else{
  576. this.offline();
  577. }
  578. window.setTimeout(this.checkOnline.bind(this), 10000);
  579. }.bind(this));
  580. }
  581. },
  582. online: function(){
  583. if (this.data.onlineStatus!=="online"){
  584. if (this.img.status==="success") this.data.onlineStatus="online";
  585. if (this.onlineTree){
  586. this.parent = this.onlineTree;
  587. this.treeItem.destroy();
  588. this.treeItem = this.parent.appendChild(this.getTreenodeObj());
  589. }
  590. this.setOnlineFlag();
  591. }
  592. },
  593. offline: function(){
  594. if (this.data.onlineStatus!=="offline"){
  595. this.data.onlineStatus="offline";
  596. if (this.img.status==="success") this.data.onlineStatus="offline";
  597. if (this.offlineTree){
  598. this.parent = this.offlineTree;
  599. this.treeItem.destroy();
  600. this.treeItem = this.parent.appendChild(this.getTreenodeObj());
  601. //this.treeItem = this.parent.appendChild(this.getTreenodeObj());
  602. }
  603. this.setOnlineFlag();
  604. }
  605. },
  606. setOnlineFlag: function(){
  607. if (!this.onlineFlagNode){
  608. this.onlineFlagNode = new Element("div").inject(this.treeItem.textNode);
  609. }
  610. this.onlineFlagNode.setStyles(this.css["onlineFlagNode_"+this.data.onlineStatus]);
  611. }
  612. });