uic.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. function err_message_quietly(msg, f) {
  2. $.layer({
  3. title : false,
  4. closeBtn : false,
  5. time : 2,
  6. dialog : {
  7. msg : msg
  8. },
  9. end : f
  10. });
  11. }
  12. function ok_message_quietly(msg, f) {
  13. $.layer({
  14. title : false,
  15. closeBtn : false,
  16. time : 1,
  17. dialog : {
  18. msg : msg,
  19. type : 1
  20. },
  21. end : f
  22. });
  23. }
  24. function my_confirm(msg, btns, yes_func, no_func) {
  25. $.layer({
  26. shade : [ 0 ],
  27. area : [ 'auto', 'auto' ],
  28. dialog : {
  29. msg : msg,
  30. btns : 2,
  31. type : 4,
  32. btn : btns,
  33. yes : yes_func,
  34. no : no_func
  35. }
  36. });
  37. }
  38. // - business function -
  39. function login() {
  40. var raw = $('#ldap').prop('checked');
  41. if (raw) {
  42. useLdap = '1'
  43. } else {
  44. useLdap = '0'
  45. }
  46. $.post('/auth/login', {
  47. 'name' : $('#name').val(),
  48. 'password' : $("#password").val(),
  49. 'ldap' : useLdap
  50. }, function(json) {
  51. if (json.msg.length > 0) {
  52. err_message_quietly(json.msg);
  53. } else {
  54. ok_message_quietly('sign in successfully', function() {
  55. var redirect_url = '/user/profile';
  56. if (json.data.length > 0) {
  57. redirect_url = json.data;
  58. }
  59. location.href = redirect_url;
  60. });
  61. }
  62. }, "json");
  63. }
  64. function update_profile() {
  65. $.post('/user/profile', {
  66. 'cnname' : $("#cnname").val(),
  67. 'email' : $("#email").val(),
  68. 'phone' : $("#phone").val(),
  69. 'im' : $("#im").val(),
  70. 'qq' : $("#qq").val()
  71. }, function(json) {
  72. if (json.msg.length > 0) {
  73. err_message_quietly(json.msg);
  74. } else {
  75. ok_message_quietly("更新成功:)");
  76. }
  77. }, "json");
  78. }
  79. function change_password() {
  80. $.post('/user/chpwd', {
  81. 'old_password' : $("#old_password").val(),
  82. 'new_password' : $("#new_password").val(),
  83. 'repeat_password' : $("#repeat_password").val()
  84. }, function(json) {
  85. if (json.msg.length > 0) {
  86. err_message_quietly(json.msg);
  87. } else {
  88. ok_message_quietly("密码修改成功:)");
  89. }
  90. }, "json");
  91. }
  92. function register() {
  93. $.post('/auth/register', {
  94. 'name' : $('#name').val(),
  95. 'cnname' : $('#cnname').val(),
  96. 'email' : $('#email').val(),
  97. 'password' : $("#password").val(),
  98. 'repeat_password' : $("#repeat_password").val()
  99. }, function(json) {
  100. if (json.msg.length > 0) {
  101. err_message_quietly(json.msg);
  102. } else {
  103. ok_message_quietly('sign up successfully', function() {
  104. location.href = '/auth/login';
  105. });
  106. }
  107. }, "json");
  108. }
  109. function query_user() {
  110. var query = $("#query").val();
  111. location.href = "/user/list?query=" + query;
  112. }
  113. function query_team() {
  114. var query = $("#query").val();
  115. location.href = "/team/list?query=" + query;
  116. }
  117. function create_user() {
  118. $.post('/user/create', {
  119. 'name' : $("#name").val(),
  120. 'cnname' : $("#cnname").val(),
  121. 'email' : $("#email").val(),
  122. 'phone' : $("#phone").val(),
  123. 'im' : $("#im").val(),
  124. 'qq' : $("#qq").val(),
  125. 'password' : $("#password").val()
  126. }, function(json) {
  127. if (json.msg.length > 0) {
  128. err_message_quietly(json.msg);
  129. } else {
  130. ok_message_quietly("create user successfully");
  131. }
  132. }, "json");
  133. }
  134. function edit_user(id) {
  135. $.post('/admin/user/'+id+'/edit', {
  136. 'id': id,
  137. 'cnname' : $("#cnname").val(),
  138. 'email' : $("#email").val(),
  139. 'phone' : $("#phone").val(),
  140. 'im' : $("#im").val(),
  141. 'qq' : $("#qq").val()
  142. }, function(json) {
  143. if (json.msg.length > 0) {
  144. err_message_quietly(json.msg);
  145. } else {
  146. ok_message_quietly("更新成功:)");
  147. }
  148. }, "json");
  149. }
  150. function reset_password(id) {
  151. $.post('/admin/user/'+id+'/chpwd', {
  152. 'password' : $("#password").val()
  153. }, function(json) {
  154. if (json.msg.length > 0) {
  155. err_message_quietly(json.msg);
  156. } else {
  157. ok_message_quietly("密码重置成功:)");
  158. }
  159. }, "json");
  160. }
  161. function create_team() {
  162. $.post('/team/create', {
  163. 'name' : $("#name").val(),
  164. 'resume' : $("#resume").val(),
  165. 'users' : $("#users").val()
  166. }, function(json) {
  167. if (json.msg.length > 0) {
  168. err_message_quietly(json.msg);
  169. } else {
  170. ok_message_quietly('create team successfully');
  171. }
  172. }, "json");
  173. }
  174. function edit_team(tid) {
  175. $.post('/team/'+tid+'/edit', {
  176. 'resume' : $("#resume").val(),
  177. 'users' : $("#users").val(),
  178. 'id': tid
  179. }, function(json) {
  180. if (json.msg.length > 0) {
  181. err_message_quietly(json.msg);
  182. } else {
  183. ok_message_quietly('edit team successfully');
  184. }
  185. }, "json");
  186. }
  187. function delete_user(uid) {
  188. my_confirm("真的要删除么?通常只有离职的时候才需要删除", [ '确定', '取消' ], function() {
  189. $.post('/admin/user/'+uid+'/delete', {
  190. }, function(json) {
  191. if (json.msg.length > 0) {
  192. err_message_quietly(json.msg);
  193. } else {
  194. ok_message_quietly('delete user successfully', function() {
  195. location.reload();
  196. });
  197. }
  198. }, "json");
  199. }, function() {
  200. });
  201. }
  202. function delete_team(id) {
  203. my_confirm("真的真的要删除么?", [ '确定', '取消' ], function() {
  204. $.post('/team/'+id+'/delete', {}, function(json) {
  205. if (json.msg.length > 0) {
  206. err_message_quietly(json.msg);
  207. } else {
  208. ok_message_quietly('delete team successfully', function() {
  209. location.reload();
  210. });
  211. }
  212. }, "json");
  213. }, function() {
  214. });
  215. }
  216. function set_role(uid, obj) {
  217. var role = obj.checked ? '1' : '0';
  218. $.post('/admin/user/'+uid+'/role', {
  219. 'role' : role
  220. }, function(json) {
  221. if (json.msg.length > 0) {
  222. err_message_quietly(json.msg);
  223. location.reload();
  224. } else {
  225. if (role == '1') {
  226. ok_message_quietly('成功设置为管理员:)');
  227. } else if (role == '0') {
  228. ok_message_quietly('成功取消管理员权限:)');
  229. }
  230. }
  231. }, "json");
  232. }