mine.js 3.0 KB

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