orgIndex.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. var menu;
  2. var groupMenu;
  3. var currentMenu;
  4. var actionNode;
  5. var olineObj, orgObj, groupObj;
  6. $(function() {
  7. initTab();
  8. loadMenu();
  9. loadGroupMenu();
  10. initTabTree();
  11. });
  12. function initTab(){
  13. try{
  14. var h = $(".portlet_content", window.parent.document).height();
  15. $("#tab1").height(h - 10);
  16. $("#tab2").height(h - 10);
  17. $("#tab1 .org_tree").height(h - 40);
  18. $(".org_tree").scroll(function(){
  19. menu.hide();
  20. groupMenu.hide();
  21. });
  22. }catch(e){}
  23. }
  24. function initTabTree(){
  25. try{
  26. olineObj = onlineTree();
  27. $("#tab1").ligerTab({
  28. contextmenu : false,
  29. onAfterSelectTabItem : function(tabid) {
  30. if (tabid == "tabitem1" && !olineObj) {
  31. olineObj = onlineTree();
  32. }
  33. if (tabid == "tabitem2" && !orgObj) {
  34. orgObj = orgTree();
  35. }
  36. if (tabid == "tabitem3" && !groupObj) {
  37. groupObj = groupTree();
  38. }
  39. }
  40. });
  41. }catch(e){}
  42. }
  43. function loadMenu() {
  44. try{
  45. var param = {'type':"menu"};
  46. sendAsyncAjax(param, "loadOrgIndex.do", "json", processMenu);
  47. }catch(e){}
  48. }
  49. function processMenu(data) {
  50. var userMenu = [];
  51. try{
  52. if(data==null||!data)return;
  53. for(var i = 0; i < data.length; i++) {
  54. userMenu.push({
  55. id:data[i].clickName,
  56. text : data[i].menuText,
  57. action : data[i].menuAction,
  58. click : eval(data[i].clickName)
  59. });
  60. }
  61. menu = $.ligerMenu({
  62. top : 100,
  63. left : 100,
  64. width : 120,
  65. items : userMenu
  66. });
  67. currentMenu = $.ligerMenu({
  68. top : 100,
  69. left : 100,
  70. width : 120,
  71. items : userMenu
  72. });
  73. currentMenu.removeItem('sendIMEvent');
  74. }catch(e){
  75. }
  76. }
  77. function loadGroupMenu() {
  78. try{
  79. var param = {'type':"all"};
  80. sendAsyncAjax(param, "loadOrgIndex.do", "json", processAllMenu);
  81. }catch(e){}
  82. }
  83. function processAllMenu(data) {
  84. var userMenu = [];
  85. for ( var i = 0; i < data.length; i++) {
  86. userMenu.push({
  87. text : data[i].menuText,
  88. action : data[i].menuAction,
  89. click : eval(data[i].clickName)
  90. });
  91. }
  92. groupMenu = $.ligerMenu({
  93. top : 100,
  94. left : 100,
  95. width : 120,
  96. items : userMenu
  97. });
  98. }
  99. function onlineTree() {
  100. try{
  101. $("#onlineList").empty();
  102. var m = "";
  103. m = $("#onlineList").ligerTree({
  104. url : "loadOnlineTree.do?type=user&t=" + new Date().getTime(),
  105. checkbox : false,
  106. childIcon : 'folder',
  107. idFieldName : 'id',
  108. parentIDFieldName : 'pid',
  109. slide : false,
  110. nodeWidth : 120,
  111. attribute : [ 'id', 'url', 'level' ],
  112. onContextmenu : function(node, e) {
  113. if(m){
  114. $("#onlineList").find(".l-selected").removeClass("l-selected");
  115. m.selectNode(node.target);
  116. }
  117. loadContextMenu(node, e);
  118. return false;
  119. },
  120. onBeforeAppend:function(parentNode, newdata){
  121. $("#onlineList").empty();
  122. },
  123. onSuccess : function() {
  124. filterFolder(5);
  125. }
  126. });
  127. return m;
  128. }catch(e){}
  129. }
  130. function orgTree() {
  131. $("#orgList").empty();
  132. var m = "";
  133. m = $("#orgList").ligerTree({
  134. url : "orgTree.do?type=user&t=" + new Date().getTime(),
  135. checkbox : false,
  136. childIcon : 'folder',
  137. idFieldName : 'id',
  138. parentIDFieldName : 'pid',
  139. slide : false,
  140. nodeWidth : 120,
  141. attribute : [ 'id', 'url', 'level', 'isexpand' ],
  142. onContextmenu : function(node, e) {
  143. if(m){
  144. $("#orgList").find(".l-selected").removeClass("l-selected");
  145. m.selectNode(node.target);
  146. }
  147. loadContextMenu(node,e);
  148. return false;
  149. }
  150. });
  151. return m;
  152. }
  153. function groupTree() {
  154. $("#groupList").empty();
  155. var m = "";
  156. m = $("#groupList").ligerTree({
  157. url : "loadGroupTree.do?type=user&t=" + new Date().getTime(),
  158. checkbox : false,
  159. childIcon : 'folder',
  160. idFieldName : 'id',
  161. parentIDFieldName : 'pid',
  162. slide : false,
  163. nodeWidth : 120,
  164. attribute : [ 'id', 'url', 'level' ],
  165. onContextmenu : function(node, e) {
  166. if(m){
  167. $("#groupList").find(".l-selected").removeClass("l-selected");
  168. m.selectNode(node.target);
  169. }
  170. loadContextMenu(node, e);
  171. return false;
  172. }
  173. });
  174. return m;
  175. }
  176. function loadContextMenu(node,e){
  177. var childNode = node.data.children;
  178. var treeH = $(".org_tree").height();
  179. var top = e.pageY;
  180. actionNode = node;
  181. var tempMenu;
  182. if (!childNode) {
  183. var currentUserId = $("#currentUserId").val();
  184. if("-"+currentUserId == node.data.id){
  185. tempMenu = currentMenu;
  186. menu.hide();
  187. }else{
  188. tempMenu = menu;
  189. currentMenu.hide();
  190. }
  191. var mh = tempMenu.getItemCount()*23;
  192. if(top>treeH-mh){
  193. top = e.pageY-mh;
  194. }
  195. tempMenu.show({
  196. top : top,
  197. left : e.pageX
  198. });
  199. groupMenu.hide();
  200. } else {
  201. var gmh = groupMenu.getItemCount()*23;
  202. if(top>treeH-gmh){
  203. top = e.pageY-gmh;
  204. }
  205. groupMenu.show({
  206. top : top,
  207. left : e.pageX
  208. });
  209. currentMenu.hide();
  210. menu.hide();
  211. }
  212. }
  213. function filterFolder(n) {
  214. while (n > 1) {
  215. $("li[outlinelevel=" + n + "]").each(function() {
  216. var itemid = $(this).attr("id");
  217. if (itemid.indexOf("-") == -1) {
  218. var children = $(".l-children li", this);
  219. if (children.length == 0) {
  220. $(this).remove();
  221. }
  222. }
  223. });
  224. n--;
  225. }
  226. $("ul#onlineList").find(".l-expandable-close").click();
  227. }
  228. var imDialog;
  229. function viewInfoEvent(item, i) {
  230. var nodeId = actionNode.data.id;
  231. if (nodeId>0) {
  232. openTopDialog({
  233. title : "部门信息",
  234. url : "viewUser.do?type=group&nodeId=" + nodeId,
  235. width : 500,
  236. height : 200
  237. });
  238. } else {
  239. openTopDialog({
  240. title : "用户信息",
  241. url : "viewUser.do?type=user&nodeId=" + nodeId,
  242. width : 500,
  243. height : 500
  244. });
  245. }
  246. }
  247. function sendEvent(item, type) {
  248. var url = "";
  249. var nodeId = actionNode.data.id;
  250. if (nodeId>0) {
  251. url = "sendEvent.do?type=" + type + "&sendType=group&nodeId=" + nodeId;
  252. } else {
  253. url = "sendEvent.do?type=" + type + "&sendType=user&nodeId=" + nodeId;
  254. }
  255. addTab(item.action, item.text, url, true, false);
  256. }
  257. function sendMsgEvent(item, i) {
  258. sendEvent(item, "sendMsg");
  259. }
  260. function sendEmailEvent(item, i) {
  261. sendEvent(item, "sendEmail");
  262. }
  263. function sendSmsEvent(item, i) {
  264. sendEvent(item, "sendSms");
  265. }
  266. function sendIMEvent(item, i) {
  267. var nodeId = actionNode.data.id;
  268. var t = actionNode.data.text;
  269. var currentUserId = $("#currentUserId").val();
  270. if("-"+currentUserId == nodeId){
  271. addError("不能和自己对话");
  272. return;
  273. }
  274. var task = getTask(nodeId);
  275. if(task.length>0){
  276. $(task).click();
  277. nodeId = 1;
  278. }
  279. if (nodeId<0) {
  280. imDialog = openTopDialog({onClose:closeTopDialog,id:nodeId,height: 500, url: 'openMI.do?type=open&sendUserName='+t+'&toUser='+nodeId, width: 550, showMax: true, showMin: true, isResize: true,title:t,isHidden:false});
  281. }
  282. }
  283. function openIMList(e,userId,t){
  284. $(e).parent().remove();
  285. var l = $("#msgBoxDialog").find("li");
  286. if(l.length==0){
  287. imMsgBoxDialog.close();
  288. window.top.document.title=$("#topTitle").val();
  289. clearTimeout(titleTipTime);
  290. clearTimeout(blinkTime);
  291. $("#imCount").html(0);
  292. im_imgCount.style.visibility = "visible";
  293. }
  294. openTopDialog({onClose:closeTopDialog,id:"-"+userId,height: 500, url: 'openMI.do?type=open&toUser='+userId, width: 550, showMax: true, showMin: true, isResize: true,title:t,isHidden:false});
  295. }
  296. function getTask(nodeId){
  297. return $("#task_"+nodeId,window.top.document);
  298. }
  299. function closeTopDialog(dialog,options){
  300. var iframeId = $(dialog.jiframe).attr("id");
  301. parent.parent.document.getElementById(iframeId).contentWindow.stopTime();
  302. return true;
  303. }
  304. function openTab(i){
  305. if(i=='1'){
  306. loadUnlineMsg();
  307. }
  308. if(i=='2'){
  309. addTab("toRecieveMsgList.do","我的消息","toRecieveMsgList.do", true, false);
  310. }
  311. if(i=='3'){
  312. addTab("receiveMailAction.do?task=list","我的邮件","receiveMailAction.do?task=list", true, false);
  313. }
  314. }
  315. function loadUnlineMsg(){
  316. var imCount = parseInt($("#imCount").html(),10);
  317. if(imCount>0){
  318. var param = {'type':'unlineMsg'};
  319. sendAsyncAjax(param,"openMI.do","json",loadUnlineMsgProcess);
  320. }
  321. }
  322. var imMsgBoxDialog;
  323. function loadUnlineMsgProcess(data){
  324. var html = "";
  325. if(data==null||!data)return;
  326. for(var i=0;i<data.length;i++){
  327. var im = data[i];
  328. var isExist = $("#"+im.sendUser);
  329. if(isExist.length==0){
  330. html += "<li style='height:15px;padding-top:3px;' id='"+im.sendUser+"'><a href='#' onclick=openIMList(this,'"+im.sendUser+"','"+im.sendUserName+"')>"+im.sendUserName+"</a></li>";
  331. }
  332. }
  333. var ct = "<ul id='msgBoxDialog'>"+html+"</ul>";
  334. imMsgBoxDialog = $.ligerDialog.open({ height: 200, content:ct, width: 150,isHidden:false});
  335. }