887428882265f100b7354edab601aea79022ba11.svn-base 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * @class 系统组织机构管理类
  3. * 功能:管理组织机构,该菜单内容只有“系统管理员”才有访问权限
  4. *
  5. * @author Jiamd
  6. * @since v1.0 2014-08-01
  7. *
  8. */
  9. com.sinosoft.lz.system.department.depart = function(){
  10. var _this = this;
  11. _this.zTree = null;
  12. _this.tab = null;
  13. _this.nodes = [];
  14. _this.Setting = null;
  15. _this.Settinga = null;
  16. //示例2相关
  17. var setting = {
  18. async: {
  19. enable: true,
  20. dataType: 'JSON',
  21. //返回的JSON数据的名字
  22. dataName: 'treeNodes',
  23. contentType: "application/json",
  24. url:$.pathname() + '/ws/dept/DeptService/getDepartTree',
  25. autoParam: ["id", "name", "name=reName"]
  26. },
  27. callback: {
  28. onClick:zTreeSelect,
  29. onRightClick: OnRightClick
  30. }
  31. };
  32. /**
  33. * 加载数据
  34. */
  35. _this.initTree = function () {
  36. _this.zTree = $.fn.zTree.init($("#tree"),setting);
  37. _this.tab = new TabView( {
  38. containerId :'tab_menu',
  39. pageid :'page',
  40. cid :'tab1',
  41. position :"top"
  42. });
  43. };
  44. //鼠标点击右键处理
  45. function OnRightClick(event, treeId, treeNode) {
  46. //在节点之外显示一种菜单
  47. if (!treeNode && event.target.tagName.toLowerCase() != "button" && $(event.target).parents("a").length == 0) {
  48. _this.zTree.cancelSelectedNode();
  49. showRMenu("root", event.clientX, event.clientY);
  50. //在节点里面显示另一种菜单
  51. } else if(treeNode && !treeNode.noR) {
  52. _this.zTree.selectNode(treeNode);
  53. showRMenu(treeNode.menuType, event.clientX, event.clientY);
  54. }
  55. }
  56. //根据设置弹出不同的右键菜单
  57. function showRMenu(type, x, y) {
  58. $("#rMenu ul").show();
  59. if(type == "root") {//树节点外只保留添加和恢复
  60. $("#addUnit").show();
  61. $("#addDept").show();
  62. $("#addPerson").show();
  63. $("#DeleteDept").hide();
  64. $("#DeletePerson").hide();
  65. }else if(type == "nonLeafMenu") {//父节点保留添加和删除
  66. $("#addDept").show();
  67. $("#addPerson").show();
  68. $("#DeleteDept").show();
  69. $("#addUnit").hide();
  70. $("#DeletePerson").hide();
  71. }else if(type == "leafMenu") {//子节点保留选择和删除
  72. $("#DeletePerson").show();
  73. $("#addUnit").hide();
  74. $("#addDept").hide();
  75. $("#addPerson").hide();
  76. $("#DeleteDept").hide();
  77. }
  78. $("#rMenu").css({"top":y+"px", "left":x+"px", "visibility":"visible"});
  79. //点击菜单外时隐藏菜单
  80. $("body").bind("mousedown", onBodyMouseDown);
  81. }
  82. //点击菜单项时隐藏菜单
  83. function hideRMenu() {
  84. if ($("#rMenu")) $("#rMenu").css({"visibility": "hidden"});
  85. $("body").unbind("mousedown", onBodyMouseDown);
  86. }
  87. //点击菜单外时隐藏菜单
  88. function onBodyMouseDown(event){
  89. if (!(event.target.id == "rMenu" || $(event.target).parents("#rMenu").length > 0)) {
  90. $("#rMenu").css({"visibility" : "hidden"});
  91. }
  92. }
  93. //点击树节点
  94. function zTreeSelect(event,treeId,treeNode) {
  95. var type = treeNode.type;
  96. var url = "DeptEdit.jsp?id="+treeNode.id+"&objectId="+treeNode.objectId;
  97. if(type=='person'){
  98. url = "PersonEdit.jsp?id="+treeNode.id+"&objectId="+treeNode.objectId;
  99. }
  100. tabAddHandler(treeNode.id,treeNode.name,url);
  101. }
  102. function addDept(){
  103. hideRMenu();
  104. var node = _this.zTree.getSelectedNodes()[0];
  105. tabAddHandler(node.objectId,"新增部门","DeptEdit.jsp?id="+node.id+"&objectId="+node.objectId);
  106. }
  107. function addPerson(){
  108. hideRMenu();
  109. var node = _this.zTree.getSelectedNodes()[0];
  110. tabAddHandler(node.objectId,"新增用户","PersonEdit.jsp?id="+node.id+"&objectId="+node.objectId);
  111. }
  112. function deleteDept(){
  113. }
  114. function deletePerson(){
  115. }
  116. /**
  117. * 切换tab
  118. */
  119. _this.tabAddHandler = function (mid,mtitle,murl){
  120. _this.tab.close(mid);
  121. _this.tab.add( {
  122. id :mid,
  123. title :mtitle,
  124. url :murl,
  125. isClosed :true
  126. });
  127. _this.tab.activate(mid);
  128. };
  129. return {
  130. /**
  131. * 功能:初始化
  132. */
  133. init : function(){
  134. _this.initTree();
  135. },
  136. addDept : function (){
  137. // alert(12313);
  138. hideRMenu();
  139. var node = _this.zTree.getSelectedNodes()[0];
  140. _this.tabAddHandler(node.objectId,"新增部门","DeptEdit.jsp?id="+node.id+"&objectId="+node.objectId);
  141. }
  142. };
  143. }();
  144. $(function(){
  145. com.sinosoft.lz.system.department.depart.init();
  146. });
  147. $.depart = com.sinosoft.lz.system.department.depart;