personshift.js 8.2 KB

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