group_add.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. $(function () {
  2. $('.skin-minimal input').iCheck({
  3. checkboxClass: 'icheckbox-blue',
  4. radioClass: 'iradio-blue',
  5. increaseArea: '20%'
  6. });
  7. $("#form-admin-group-add").validate({
  8. rules:{
  9. name:{
  10. required:true,
  11. minlength: 1,
  12. maxlength: 60,
  13. remote: {
  14. url: pagePath+"/admin/group/isExist",
  15. type: "get",
  16. data: {
  17. name: function () {
  18. return $("#name").val();
  19. }
  20. }
  21. }
  22. },
  23. remark:{
  24. minlength: 1,
  25. maxlength: 200
  26. }
  27. },
  28. messages : {
  29. name : {
  30. remote: "该组名已经存在!"
  31. }
  32. },
  33. onkeyup:false,
  34. focusCleanup:true,
  35. focusInvalid:false,
  36. success:"valid",
  37. submitHandler:function(form){
  38. var userIds=[]
  39. $(".add_users tr").each(function(){
  40. userIds.push($(this).find(".user_id").attr("id"));
  41. });
  42. $("#userIds").val(userIds);
  43. $(form).ajaxSubmit({
  44. type: 'post',
  45. url: pagePath+"/admin/group/saveGroup",
  46. dataType:"json",
  47. success: function(data){
  48. if (data.success) {
  49. succeedMessage(data.message);
  50. setTimeClose();
  51. }else {
  52. errorMessage(data.message);
  53. }
  54. }
  55. });
  56. return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。
  57. }
  58. });
  59. $("#form-admin-department-group-add").validate({
  60. rules:{
  61. name:{
  62. required:true,
  63. minlength: 1,
  64. maxlength: 60,
  65. },
  66. remark:{
  67. minlength: 1,
  68. maxlength: 200
  69. }
  70. },
  71. messages : {},
  72. onkeyup:false,
  73. focusCleanup:true,
  74. focusInvalid:false,
  75. success:"valid",
  76. submitHandler:function(form){
  77. var userIds=[]
  78. $(".add_users tr").each(function(){
  79. userIds.push($(this).find(".user_id").attr("id"));
  80. });
  81. $("#departmentIds").val(userIds.toString());
  82. $(form).ajaxSubmit({
  83. type: 'post',
  84. url: pagePath+"/admin/group/saveDepartmentGroup",
  85. dataType:"json",
  86. success: function(data){
  87. if (data.success) {
  88. succeedMessage(data.message);
  89. setTimeClose();
  90. }else {
  91. errorMessage(data.message);
  92. }
  93. }
  94. });
  95. return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。
  96. }
  97. });
  98. $("#form-admin-department-group-edit").validate({
  99. rules:{
  100. name:{
  101. required:true,
  102. minlength: 1,
  103. maxlength: 60,
  104. },
  105. remark:{
  106. minlength: 1,
  107. maxlength: 200
  108. }
  109. },
  110. messages : {},
  111. onkeyup:false,
  112. focusCleanup:true,
  113. focusInvalid:false,
  114. success:"valid",
  115. submitHandler:function(form){
  116. var userIds=[]
  117. $(".add_users tr").each(function(){
  118. userIds.push($(this).find(".user_id").attr("id"));
  119. });
  120. $("#departmentIds").val(userIds.toString());
  121. $(form).ajaxSubmit({
  122. type: 'post',
  123. url: pagePath+"/admin/group/editDepartmentGroup",
  124. dataType:"json",
  125. success: function(data){
  126. if (data.success) {
  127. succeedMessage(data.message);
  128. setTimeClose();
  129. }else {
  130. errorMessage(data.message);
  131. }
  132. }
  133. });
  134. return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。
  135. }
  136. });
  137. });
  138. /*选择用户*/
  139. function select_user(title, url, w, h) {
  140. layer_show(title, pagePath+url, w, h);
  141. }
  142. function addUsers(userLists){
  143. var userIds=[];
  144. $(".no_data").remove();
  145. var html="";
  146. $(".add_users tr").each(function(){
  147. userIds.push($(this).find(".user_id").attr("id"));
  148. });
  149. // debugger;
  150. $.each(userLists, function(index, obj) {
  151. if(!array_contain(userIds,obj.id)){
  152. html+="<tr class='text-c'>";
  153. html+="<td>"+obj.nick_name+"</td>";
  154. html+="<td>"+obj.user_name+"</td>";
  155. html+="<td>"+obj.role_names+"</td>";
  156. html+="<td>"+obj.department_name+"</td>";
  157. html+="<td class='user_id' id="+obj.id+" onclick='removeLine(this,"+obj.id+")'>删除</td>";
  158. html+="</tr>";
  159. }
  160. });
  161. $(".add_users").append(html);
  162. }
  163. function removeLine(obj) {
  164. $(obj).parents("tr").remove();
  165. }
  166. function array_contain(array, obj){
  167. for (var i = 0; i < array.length; i++){
  168. if (array[i] == obj)
  169. return true;
  170. }
  171. return false;
  172. }
  173. //选择部门select_department
  174. function select_department(title, url, w, h) {
  175. layer_show(title, pagePath+url, w, h);
  176. }
  177. function addDepartment(departmentList){
  178. var departmentIds=[];
  179. $(".no_data").remove();
  180. var html="";
  181. $(".add_users tr").each(function(){
  182. departmentIds.push($(this).find(".user_id").attr("id"));
  183. });
  184. //debugger;
  185. $.each(departmentList, function(index, obj) {
  186. if(!array_contain(departmentIds,obj.id)){
  187. html+="<tr class='text-c'>";
  188. html+="<td>"+obj.name+"</td>";
  189. html+="<td class='user_id' id="+obj.id+" onclick='removeLine(this,"+obj.id+")'>删除</td>";
  190. html+="</tr>";
  191. }
  192. });
  193. $(".add_users").append(html);
  194. }