group_edit.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. $(function () {
  2. $("#form-admin-group-edit").validate({
  3. rules:{
  4. name:{
  5. required:true,
  6. minlength: 1,
  7. maxlength: 60,
  8. remote: {
  9. url: pagePath+"/admin/group/isExist",
  10. type: "get",
  11. data: {
  12. name: function () {
  13. return $("#name").val();
  14. },
  15. id:$("#id").val()
  16. }
  17. }
  18. },
  19. perms:{
  20. required:true
  21. },
  22. remark:{
  23. minlength: 1,
  24. maxlength: 200
  25. }
  26. },
  27. messages : {
  28. name : {
  29. remote: "该组名已经存在!"
  30. }
  31. },
  32. onkeyup:false,
  33. focusCleanup:true,
  34. focusInvalid:false,
  35. success:"valid",
  36. submitHandler:function(form){
  37. var userIds=[]
  38. $(".add_users tr").each(function(){
  39. userIds.push($(this).find(".user_id").attr("id"));
  40. });
  41. $("#userIds").val(userIds);
  42. $(form).ajaxSubmit({
  43. type: 'POST',
  44. url: pagePath+"/admin/group/updateGroup",
  45. dataType:"json",
  46. success: function(data){
  47. if (data.success) {
  48. succeedMessage(data.message);
  49. setTimeClose();
  50. }else {
  51. errorMessage(data.message);
  52. }
  53. }
  54. });
  55. return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。
  56. }
  57. });
  58. });
  59. /*选择用户*/
  60. function select_user(title, url, w, h) {
  61. layer_show(title, pagePath+url, w, h);
  62. }
  63. function addUsers(userLists){
  64. var userIds=[];
  65. $(".no_data").remove();
  66. var html="";
  67. $(".add_users tr").each(function(){
  68. userIds.push($(this).find(".user_id").attr("id"));
  69. });
  70. debugger;
  71. $.each(userLists, function(index, obj) {
  72. if(!array_contain(userIds,obj.id)){
  73. html+="<tr class='text-c'>";
  74. html+="<td>"+obj.nick_name+"</td>";
  75. html+="<td>"+obj.user_name+"</td>";
  76. html+="<td>"+obj.role_names+"</td>";
  77. html+="<td>"+obj.department_name+"</td>";
  78. html+="<td class='user_id' id="+obj.id+" onclick='removeLine(this,"+obj.id+")'>删除</td>";
  79. html+="</tr>";
  80. }
  81. });
  82. $(".add_users").append(html);
  83. }
  84. function removeLine(obj) {
  85. $(obj).parents("tr").remove();
  86. }
  87. function array_contain(array, obj){
  88. for (var i = 0; i < array.length; i++){
  89. if (array[i] == obj)
  90. return true;
  91. }
  92. return false;
  93. }