You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
7.6 KiB

3 years ago
  1. $(function(){
  2. $('a[data-toggle="tab"]').on('shown', function (e) {
  3. //e.target // activated tab
  4. //e.relatedTarget // previous tab
  5. console.log($(e.target).attr("href"));
  6. })
  7. //展示第一个tab
  8. $("#myTab a:first").tab("show");
  9. var item_id = $("#item_id").val() ;
  10. //获取基础信息
  11. get_base_info() ;
  12. function get_base_info(){
  13. $.get(
  14. DocConfig.server+"/api/item/detail",
  15. {"item_id":item_id},
  16. function(data){
  17. if (data.error_code === 0 ) {
  18. //console.log(data.data);
  19. $("#item_name").val(data.data.item_name);
  20. $("#item_description").val(data.data.item_description);
  21. $("#item_domain").val(data.data.item_domain);
  22. $("#password").val(data.data.password);
  23. $("#password").attr('type','password');
  24. }else{
  25. $.alert(data.error_message);
  26. }
  27. },
  28. "json"
  29. );
  30. }
  31. //保存项目基础信息
  32. $("#item_save").click(function(){
  33. var item_name = $("#item_name").val();
  34. var item_description = $("#item_description").val();
  35. var item_domain = $("#item_domain").val();
  36. var password = $("#password").val();
  37. $.post(
  38. DocConfig.server+"/api/item/update",
  39. {"item_id":item_id,"item_name":item_name,"item_description":item_description,"item_domain":item_domain,"password":password},
  40. function(data){
  41. if (data.error_code === 0 ) {
  42. $.msg('保存成功',{"time":1000});
  43. get_base_info() ;
  44. }else{
  45. $.alert(data.error_message);
  46. }
  47. },
  48. "json"
  49. );
  50. return false;
  51. });
  52. //点击转让按钮,弹出modal
  53. $("#attorn-btn").click(function(){
  54. $('#attorn-modal').modal({
  55. "backdrop":'static'
  56. });
  57. });
  58. //监听转让
  59. $("#attorn_save").click(function(){
  60. var username = $("#attorn_username").val();
  61. var password = $("#attorn_password").val();
  62. $.post(
  63. DocConfig.server+"/api/item/attorn",
  64. {"username": username ,"item_id": item_id , "password": password },
  65. function(data){
  66. if (data.error_code == 0) {
  67. $.msg('转让成功,正在跳转回主页..',{"time":3000});
  68. //跳转
  69. setTimeout(function(){
  70. window.location.href="?s=/home/item/index";
  71. },3000)
  72. }else{
  73. $.alert(data.error_message);
  74. }
  75. },
  76. "json"
  77. );
  78. return false;
  79. });
  80. //删除项目
  81. $("#delete-item-btn").click(function(){
  82. $('#delete-item-modal').modal({
  83. "backdrop":'static'
  84. });
  85. });
  86. //监听删除
  87. $("#delete_item_save").click(function(){
  88. var password = $("#delete_item_password").val();
  89. $.post(
  90. DocConfig.server+"/api/item/delete",
  91. {"item_id": item_id , "password": password },
  92. function(data){
  93. if (data.error_code == 0) {
  94. $.msg('删除成功,正在跳转回主页..',{"time":3000});
  95. //跳转
  96. setTimeout(function(){
  97. window.location.href="?s=/home/item/index";
  98. },3000)
  99. }else{
  100. $.alert(data.error_message);
  101. }
  102. },
  103. "json"
  104. );
  105. return false;
  106. });
  107. //点击添加成员,弹出modal
  108. $("#add-member-btn").click(function(){
  109. $('#member-modal').modal({
  110. "backdrop":'static'
  111. });
  112. });
  113. //获取成员列表
  114. get_member_list();
  115. function get_member_list(){
  116. $.get(
  117. DocConfig.server+"/api/member/getList",
  118. {"item_id":item_id},
  119. function(data){
  120. $("#member-list").html('');
  121. if (data.error_code === 0 ) {
  122. //console.log(data.data);
  123. var json = data.data ;
  124. if (json.length > 0 ) {
  125. for (var i = 0; i < json.length; i++) {
  126. var html = '<tr>'
  127. +'<td><div class="type-parent">'+json[i].username+'</div></td>'
  128. +'<td><div class="type-parent">'+json[i].addtime+'</div></td>'
  129. +'<td><div class="type-parent">'+json[i].member_group+'</div></td>'
  130. +'<td><a href="#" class="member-delete" data-id="'+json[i].item_member_id+'">删除</a></td>'
  131. +'</tr>';
  132. $("#member-list").append(html);
  133. };
  134. };
  135. }else{
  136. $.alert(data.error_message);
  137. }
  138. },
  139. "json"
  140. );
  141. }
  142. //添加成员
  143. $("#member_save").click(function(){
  144. var username = $("#member_username").val();
  145. var member_group_id = $("#member_group_id").is(':checked') ? 0 : 1 ;
  146. $.post(
  147. DocConfig.server+"/api/member/save",
  148. {"item_id": item_id , "username": username ,"member_group_id":member_group_id },
  149. function(data){
  150. if (data.error_code == 0) {
  151. $('#member-modal').modal('hide');
  152. $("#member_username").val('');
  153. $("#member_group_id").removeAttr("checked");
  154. $.msg('添加成功',{"time":1000});
  155. get_member_list();
  156. }else{
  157. $.alert(data.error_message);
  158. }
  159. },
  160. "json"
  161. );
  162. return false;
  163. });
  164. //删除成员
  165. $("#member-list").on("click",'.member-delete',function(){
  166. var item_member_id = $(this).data("id");
  167. $.confirm("确定删除成员吗",{},function(){
  168. $.post(
  169. DocConfig.server+"/api/member/delete",
  170. {"item_id": item_id , "item_member_id": item_member_id },
  171. function(data){
  172. if (data.error_code == 0) {
  173. $.msg('删除成功',{"time":1000});
  174. get_member_list();
  175. }else{
  176. $.alert(data.error_message);
  177. }
  178. },
  179. "json"
  180. );
  181. });
  182. return false;
  183. });
  184. //归档项目
  185. $("#archive-item-btn").click(function(){
  186. $('#archive-item-modal').modal({
  187. "backdrop":'static'
  188. });
  189. });
  190. //监听归档
  191. $("#archive_item_save").click(function(){
  192. var password = $("#archive_item_password").val();
  193. $.post(
  194. DocConfig.server+"/api/item/archive",
  195. {"item_id": item_id , "password": password },
  196. function(data){
  197. if (data.error_code == 0) {
  198. $.msg('归档成功',{"time":3000});
  199. $('#archive-item-modal').modal('hide');
  200. }else{
  201. $.alert(data.error_message);
  202. }
  203. },
  204. "json"
  205. );
  206. return false;
  207. });
  208. //获取item api_key信息
  209. get_api_info() ;
  210. function get_api_info(){
  211. $.get(
  212. DocConfig.server+"/api/item/getKey",
  213. {"item_id":item_id},
  214. function(data){
  215. if (data.error_code === 0 ) {
  216. //console.log(data.data);
  217. $("#api_key").html(data.data.api_key);
  218. $("#api_token").html(data.data.api_token);
  219. }else{
  220. $.alert(data.error_message);
  221. }
  222. },
  223. "json"
  224. );
  225. }
  226. $("#reset_api_token").click(function(){
  227. $.post(
  228. DocConfig.server+"/api/item/resetKey",
  229. {"item_id":item_id},
  230. function(data){
  231. if (data.error_code === 0 ) {
  232. //console.log(data.data);
  233. $("#api_key").html(data.data.api_key);
  234. $("#api_token").html(data.data.api_token);
  235. }else{
  236. $.alert(data.error_message);
  237. }
  238. },
  239. "json"
  240. );
  241. return false;
  242. });
  243. });