userRole.js 8.0 KB

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