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.

147 line
3.9 KiB

3 年之前
  1. $(function(){
  2. var item_id = $("#item_id").val();
  3. $('#edit-cat').modal({
  4. "backdrop":'static'
  5. });
  6. getCatList();
  7. function getCatList(){
  8. $.get(
  9. DocConfig.server+"/api/catalog/catList",
  10. { "item_id": item_id },
  11. function(data){
  12. $("#show-second-cat").html('');
  13. $("#show-third-cat").html('');
  14. if (data.error_code == 0) {
  15. json = data.data;
  16. console.log(json);
  17. for (var i = 0; i < json.length; i++) {
  18. if (json[i].level == 2 ) {
  19. cat_html ='<a class="badge badge-info single-cat " href="?s=home/catalog/edit&cat_id='+json[i].cat_id+'&item_id='+json[i].item_id+'">'+json[i].cat_name+'&nbsp;<i class="icon-edit"></i></a>';
  20. $("#show-second-cat").append(cat_html);
  21. };
  22. if (json[i].level == 3 ) {
  23. cat_html ='<a class="badge badge-info single-cat " href="?s=home/catalog/edit&cat_id='+json[i].cat_id+'&item_id='+json[i].item_id+'">'+json[i].cat_name+'&nbsp;<i class="icon-edit"></i></a>';
  24. $("#show-third-cat").append(cat_html);
  25. };
  26. };
  27. };
  28. },
  29. "json"
  30. );
  31. }
  32. /*加载二级目录,让用户选择上级目录*/
  33. secondCatList();
  34. function secondCatList() {
  35. var default_parent_cat_id = $("#default_parent_cat_id").val();
  36. var item_id = $("#item_id").val();
  37. $.get(
  38. DocConfig.server+"/api/catalog/secondCatList",
  39. {"item_id": item_id},
  40. function(data) {
  41. $("#parent_cat_id").html('<OPTION value="0">'+lang["none"]+'</OPTION>');
  42. if (data.error_code == 0) {
  43. json = data.data;
  44. console.log(json);
  45. for (var i = 0; i < json.length; i++) {
  46. cat_html = '<OPTION value="' + json[i].cat_id + '" ';
  47. if (default_parent_cat_id == json[i].cat_id) {
  48. cat_html += ' selected ';
  49. }
  50. cat_html += ' ">' + json[i].cat_name + '</OPTION>';
  51. $("#parent_cat_id").append(cat_html);
  52. };
  53. };
  54. },
  55. "json"
  56. );
  57. }
  58. //保存目录
  59. $("#save-cat").click(function(){
  60. var cat_name = $("#cat_name").val();
  61. var s_number = $("#s_number").val();
  62. var cat_id = $("#cat_id").val();
  63. var parent_cat_id = $("#parent_cat_id").val();
  64. $.post(
  65. DocConfig.server+"/api/catalog/save",
  66. {"cat_name": cat_name , "s_number": s_number , "item_id": item_id , "cat_id": cat_id, "parent_cat_id": parent_cat_id },
  67. function(data){
  68. if (data.error_code == 0) {
  69. $("#delete-cat").hide();
  70. $("#cat_name").val('');
  71. $("#s_number").val('');
  72. $("#cat_id").val('');
  73. $("#parent_cat_id").val('');
  74. secondCatList();
  75. //alert(lang["save_success"]);
  76. }else{
  77. $.alert(lang["save_fail"]);
  78. }
  79. getCatList();
  80. },
  81. "json"
  82. );
  83. return false;
  84. });
  85. //删除目录
  86. $("#delete-cat").click(function(){
  87. $.confirm(lang["confirm_to_delete"],{},function(){
  88. var cat_id = $("#cat_id").val();
  89. if (cat_id > 0 ) {
  90. $.post(
  91. DocConfig.server+"/api/catalog/delete",
  92. { "cat_id": cat_id },
  93. function(data){
  94. if (data.error_code == 0) {
  95. //alert(lang["delete_success"]);
  96. window.location.href="?s=home/catalog/edit&item_id="+item_id;
  97. }else{
  98. if (data.error_message) {
  99. $.alert(data.error_message);
  100. }else{
  101. $.alert(lang["delete_fail"]);
  102. }
  103. }
  104. },
  105. "json"
  106. );
  107. }
  108. });
  109. return false;
  110. })
  111. $(".exist-cat").click(function(){
  112. window.location.href="?s=home/item/show&item_id="+item_id;
  113. });
  114. });