following.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. function Follow(obj,data,url){
  2. if(obj.hasClass('active')) {
  3. $.ajax ({
  4. type : "DELETE",
  5. url : url,
  6. data:data,
  7. contentType: 'application/json;charset=UTF-8',
  8. success: function(response) {
  9. if (response.status === '200')
  10. {
  11. obj.text('关注').removeClass('active');
  12. } else
  13. {alert('fail');}}});
  14. }else {
  15. $.ajax ({
  16. type : "POST",
  17. url : url,
  18. data:data,
  19. contentType: 'application/json;charset=UTF-8',
  20. success: function(response) {
  21. if (response.status === '200')
  22. {
  23. obj.text('取消关注').addClass('active');
  24. } else
  25. {alert('fail');}
  26. }});
  27. }
  28. }
  29. $(document).ready(function(){
  30. $('button.topic-following').click(function(){
  31. var _$this = $(this);
  32. var url = "/following/topics";
  33. var data = JSON.stringify({
  34. topicId:_$this.attr("data-id"),
  35. });
  36. Follow(_$this,data,url);
  37. });
  38. $('button.tag-following').click(function(){
  39. var _$this = $(this);
  40. var url = "/following/tags";
  41. var data = JSON.stringify({
  42. tagId:_$this.attr("data-id"),
  43. });
  44. Follow(_$this,data,url);
  45. });
  46. $('button.user-following').click(function(){
  47. var _$this = $(this);
  48. var url = "/following/users";
  49. var data = JSON.stringify({
  50. userId:_$this.attr("data-id"),
  51. });
  52. Follow(_$this,data,url);
  53. });
  54. $('button.collect-following').click(function(){
  55. var _$this = $(this);
  56. var url = "/following/collects";
  57. var data = JSON.stringify({
  58. collectId:_$this.attr("data-id"),
  59. });
  60. Follow(_$this,data,url);
  61. });
  62. });
  63. function DoCollect(collect_url) {
  64. $(document).ready(function(){
  65. $('button#edit-collect').click(function() {
  66. var data = JSON.stringify({
  67. name:$('#name').val(),
  68. description:$('#description').val(),
  69. is_hidden:$("input[name='is_hidden']:checked").val()
  70. });
  71. $.ajax ({
  72. type : "PUT",
  73. url : collect_url,
  74. data:data,
  75. contentType: 'application/json;charset=UTF-8',
  76. success: function(response) {
  77. if (response.status === '200')
  78. {
  79. window.location.href = collect_url;
  80. }
  81. }
  82. });
  83. });
  84. $('button#delete-collect').click(function() {
  85. $.ajax ({
  86. type : "DELETE",
  87. url : collect_url,
  88. data:JSON.stringify(),
  89. contentType: 'application/json;charset=UTF-8',
  90. success: function(response) {
  91. if (response.status === '200')
  92. {
  93. window.location.href = collect_url;
  94. }
  95. }
  96. });
  97. });
  98. $('#delete-from-collect').click(function() {
  99. var _$this = $(this);
  100. var topicId = _$this.attr('data-id');
  101. var data = JSON.stringify({
  102. topicId:topicId
  103. });
  104. $.ajax ({
  105. type : "DELETE",
  106. url : '/topic/' + topicId + '/collect',
  107. data:data,
  108. contentType: 'application/json;charset=UTF-8',
  109. success: function(response) {
  110. if (response.status === '200')
  111. {
  112. _$this.parent().remove();
  113. }
  114. }
  115. });
  116. });
  117. });
  118. }