deptUserTree.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. var managerTree = "";
  2. var int_value = "";
  3. $(document).ready(
  4. function() {
  5. var currentUser = $("input[name='loginName']").val();
  6. if (currentUser == 'admin')
  7. filterStr = "";
  8. managerTree = userDeptTree(
  9. "hrUserTreeAction.do?isMultiDept=0&type=hruserdept&deptId="+$("#deptId").val(), "userTree",
  10. clickEvent, onSuccess, onAppend);
  11. /*
  12. * if(managerTree != null && managerTree != ""){ var id = -init();
  13. * if(id < 0){ var groupid = $("#groupid").val(); clearCheck(); var
  14. * params = {"userId":id,"groupid":groupid};
  15. * sendAjaxParam(params,"queryUserRole.do","json",userCallBack); } }
  16. */
  17. });
  18. function userDeptTree(treeAction, treeId, clickEvent, onSuccess, onAppend) {
  19. var manager = "";
  20. $("#" + treeId).ligerTree({
  21. url : PROJECT_NAME + "/" + changePath(treeAction),
  22. checkbox : true,
  23. folderCheckbox : false,
  24. single : false,
  25. childIcon : 'folder',
  26. idFieldName : 'id',
  27. parentIDFieldName : 'pid',
  28. openFolderEven : false,
  29. slide : false,
  30. nodeWidth : 170,
  31. attribute : [ 'id', 'pid', 'url', 'gtLevel' ],
  32. onSelect : function(node) {
  33. },
  34. onCheck : function(node) {
  35. clickEvent(node);
  36. },
  37. onAppend : function(parentNode, newdata) {
  38. if (onAppend)
  39. onAppend(parentNode, newdata);
  40. },
  41. onSuccess : function() {
  42. if (onSuccess)
  43. onSuccess();
  44. }
  45. });
  46. manager = $("#" + treeId).ligerGetTreeManager();
  47. return manager;
  48. }
  49. function onAppend(parentNode, newdata) {
  50. var initid = init();
  51. var isDept = false;
  52. var selectId = -initid + "";
  53. isAppend(parentNode, newdata, selectId, isDept);
  54. }
  55. function isAppend(parentNode, newdata, selectId, isDept) {
  56. for (var i = 0; i < newdata.length; i++) {
  57. if (newdata[i].children != undefined) {
  58. if (isDept)
  59. appendLi(newdata[i], selectId);
  60. isAppend(newdata, newdata[i].children, selectId, isDept);
  61. } else {
  62. appendLi(newdata[i], selectId);
  63. }
  64. }
  65. }
  66. function appendLi(newdata, selectId) {
  67. var id = newdata.id;
  68. var selctIds = selectId.split(",");
  69. if (isExist(id, selctIds)) {
  70. newdata.ischecked = true;
  71. }
  72. }
  73. function clickEvent(node) {
  74. var id = node.data.id;
  75. // if(id<0){
  76. // // unit = changRoleList(node,'user');
  77. // $("#selectUserId").val(id);
  78. // var params = {"userId":id,"type":"1"};
  79. // sendAsyncAjax(params,"queryUserRole.do","html",userCallBack);
  80. // }
  81. $("#userIds").val(getCheckedUsers());
  82. }
  83. function userCallBack(data) {
  84. $(".roleTr").each(function() {
  85. $(this).remove();
  86. });
  87. $("#roleTable tbody").append(data);
  88. }
  89. function checkgroup_unit(groupid) {
  90. var flag = '';
  91. $.ajax({
  92. // 请求的类型,有GET或者POST
  93. type : "POST",
  94. // 请求的url
  95. url : "checkMessage.do?date=" + new Date() + "&action=checkgroup_unit",
  96. // 向服务发送数据
  97. data : "groupid=" + groupid,
  98. // 服务器响应客户端的输出类型,text,html,xml,json
  99. async : false, // 同步
  100. dataType : "json",
  101. error : function(data) {
  102. flag = 'no';
  103. },
  104. // 服务器成功响应客户端时的回调方法
  105. success : function(data) {
  106. flag = data.unit;
  107. }
  108. });
  109. return flag;
  110. }
  111. function checkuser_unit(userid) {
  112. var flag = '';
  113. $.ajax({
  114. // 请求的类型,有GET或者POST
  115. type : "POST",
  116. // 请求的url
  117. url : "checkMessage.do?date=" + new Date() + "&action=checkuser_unit",
  118. // 向服务发送数据
  119. data : "userid=" + userid,
  120. // 服务器响应客户端的输出类型,text,html,xml,json
  121. async : false, // 同步
  122. dataType : "json",
  123. error : function(data) {
  124. flag = 'no';
  125. },
  126. // 服务器成功响应客户端时的回调方法
  127. success : function(data) {
  128. flag = data.unit;
  129. }
  130. });
  131. return flag;
  132. }
  133. function onSuccess() {
  134. managerTree.expandFirst();
  135. //managerTree.expandAll();
  136. var parm = function(data) {
  137. return true;
  138. };
  139. managerTree.selectNode(parm);
  140. var key = $("input[name='searchName']").val();
  141. if(key != ""){
  142. var itemcontent = $("div#accordion2");
  143. $("li",itemcontent).each(function(){
  144. var itemid = $(this).attr("id");
  145. if (itemid.indexOf("-") != -1) {
  146. var n = $("span", this).html();
  147. if (n.indexOf(key) == -1) {
  148. $(this).remove();
  149. }
  150. }else{
  151. var children = $(".l-children li", this);
  152. if (children.length == 0 && itemid != '${session.unit.id}') {
  153. $(this).remove();
  154. }
  155. }
  156. });
  157. }
  158. $("#userIds").val(getCheckedUsers());
  159. searchByKword();
  160. }
  161. function embed() {
  162. var e = findIframeByName("listcontent", "items");
  163. if (e != null) {
  164. clearInterval(int_value);
  165. var id = -init();
  166. if (id < 0) {
  167. var groupid = $("#groupid").val();
  168. var params = {
  169. "userId" : id,
  170. "groupid" : groupid
  171. };
  172. sendAjaxParam(params, "queryUserRole.do", "html", userCallBack);
  173. }
  174. }
  175. }
  176. //
  177. // function clearCheck(){
  178. // var items = findIframeByNames("listcontent","items");
  179. // $(items).each(function(){
  180. // $(this).attr("checked",false);
  181. // });
  182. // }
  183. function sumbitUserRole(action) {
  184. var e = findIframeByName("listcontent", "checkedItems");
  185. var isSuccess = true;
  186. var ids = $(e).val();
  187. // if(isSuccess&&ids==""){
  188. // addError("请选择角色!");
  189. // isSuccess = false;
  190. // }
  191. var checkIds = managerTree.getChecked();
  192. $("input[name='roleIds']").val(ids);
  193. var userIds = "";
  194. for (var i = 0; i < checkIds.length; i++) {
  195. var id = checkIds[i].data.id;
  196. if (id > 0)
  197. continue;
  198. userIds += "," + id;
  199. }
  200. if (isSuccess && userIds == "") {
  201. addError("请选择用户!");
  202. isSuccess = false;
  203. }
  204. if (userIds != "")
  205. userIds = userIds.substring(1);
  206. $("input[name='userIds']").val(userIds);
  207. var groupid = $("#groupid").val();
  208. var params = {
  209. "userIds" : userIds,
  210. "roleIds" : ids,
  211. "groupid" : groupid
  212. };
  213. if (isSuccess)
  214. sendAsyncAjax(params, action, "json", callback);
  215. }
  216. function callback(data) {
  217. displayAjaxMsg(data);
  218. }
  219. function moreSelect() {
  220. managerTree = $("#userTree").ligerTree({
  221. single : false
  222. });
  223. }
  224. function singleSelect() {
  225. managerTree = $("#userTree").ligerTree({
  226. single : true
  227. });
  228. // managerTree.clear();
  229. // $("#layout1").ligerLayout({ leftWidth: 250});
  230. // var height = $(".l-layout-center").height();
  231. // $("#accordion1").height(height-24);
  232. // var uid = $("#groupid").val();
  233. // var url = 'includelist.do?v=T_ROLE&k=groupid@2@'+uid+'@3';
  234. // document.getElementsByName("listcontent")[0].src = url;
  235. // var currentUser = $("input[name='loginName']").val();
  236. // if(currentUser == 'admin')filterStr="";
  237. // managerTree =
  238. // userDeptTree("userTree.do?isMultiDept=1","userTree",clickEvent,onSuccess,onAppend);
  239. }
  240. function selectRole(gxid, e) {
  241. var type = "2";
  242. if (gxid == null) {
  243. var selectNode = managerTree.getChecked();
  244. gxid = selectNode[0].data.id;
  245. type = "3";
  246. }
  247. if (gxid == '' || gxid == null) {
  248. addError("请选择人员的部门/岗位!");
  249. return;
  250. }
  251. gxid = gxid + "";
  252. if (gxid.indexOf(",") == -1) {
  253. type = "2";
  254. }
  255. var params = {
  256. "gxId" : gxid,
  257. "type" : type
  258. };
  259. $(".roleTr").removeClass("gxSelect");
  260. $(e).parent().parent().addClass("gxSelect");
  261. sendAsyncAjax(params, "queryUserRole.do", "html", selectRoleBack);
  262. }
  263. function selectRoleBack(data) {
  264. dialog = $.ligerDialog.open({
  265. title : '编辑角色',
  266. content : data,
  267. width : 450,
  268. height : 250,
  269. isHidden : false
  270. });
  271. }
  272. function addRole() {
  273. var gxId = $("#gxId").val();
  274. var roleIds = "";
  275. $("input[name='roles']:checked").each(function() {
  276. roleIds += "," + $(this).val();
  277. });
  278. if (roleIds != "")
  279. roleIds = roleIds.substring(1);
  280. if (roleIds == "") {
  281. addError("至少选择一个角色!");
  282. return;
  283. }
  284. var params = {
  285. "gxId" : gxId,
  286. "roleIds" : roleIds
  287. };
  288. sendAjaxParam(params, "addUserRole.do", "json", addRoleBack);
  289. dialog.close();
  290. var params = {
  291. "userId" : $("#selectUserId").val(),
  292. "type" : "1"
  293. };
  294. sendAsyncAjax(params, "queryUserRole.do", "html", userCallBack);
  295. $("[name='all']").attr("checked", false);
  296. }
  297. function addRoleBack(data) {
  298. displayAjaxMsg(data);
  299. }
  300. function findAllgxId() {
  301. var gxId = "";
  302. $("[name='groupUserId']:checked").each(function() {
  303. gxId += "," + $(this).val();
  304. });
  305. if (gxId != "")
  306. gxId = gxId.substring(1);
  307. return gxId;
  308. }
  309. function checkAll(e) {
  310. var all = $(e).attr("checked");
  311. if (all)
  312. all = true;
  313. else
  314. all = false;
  315. $("[name='groupUserId']").each(function() {
  316. $(this).attr("checked", all);
  317. });
  318. }
  319. function getCheckedUsers() {
  320. var notes = managerTree.getChecked();
  321. var ids = "";
  322. for (var i = 0; i < notes.length; i++) {
  323. if (notes[i].data.id < 0) {// 过滤部门节点
  324. if (ids.indexOf(notes[i].data.id) < 0) {//过滤人员id:如果有多个职位时,去掉重复人员id
  325. if (ids != "") {
  326. ids += "," + notes[i].data.id;
  327. } else {
  328. ids += notes[i].data.id;
  329. }
  330. }
  331. }
  332. }
  333. return ids;
  334. }