Main.js 29 KB

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