reportedcontent.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. define(function (require) {
  2. var elgg = require('elgg'),
  3. $ = require('jquery');
  4. $('.elgg-menu-item-report-this a, .elgg-menu-item-reportuser a').each(function () {
  5. if (!/address=/.test(this.href)) {
  6. this.href += '?address=' + encodeURIComponent(location.href) +
  7. '&title=' + encodeURIComponent(document.title);
  8. }
  9. });
  10. $(document).on('submit', '.elgg-form-reportedcontent-add', function (e) {
  11. e.preventDefault();
  12. var $form = $(this);
  13. elgg.action($form[0].action, {
  14. data: $form.serialize(),
  15. success: function (data) {
  16. if (data.status == 0) {
  17. elgg.ui.lightbox.close();
  18. }
  19. }
  20. });
  21. });
  22. $(document).on('click', '.elgg-form-reportedcontent-add .elgg-button-cancel', function (e) {
  23. if ($(this).is('#colorbox *')) {
  24. elgg.ui.lightbox.close();
  25. } else {
  26. if (history.length > 1) {
  27. history.go(-1);
  28. } else {
  29. location.href = elgg.get_site_url();
  30. }
  31. }
  32. return false;
  33. });
  34. $(document).on('click', '.elgg-item-object-reported_content', function (e) {
  35. var $clicked = $(e.target),
  36. $li = $(this);
  37. if (!$clicked.is('button[data-elgg-action]')) {
  38. return;
  39. }
  40. var action = $clicked.data('elggAction');
  41. elgg.action(action.name, {
  42. data: action.data,
  43. success: function (data) {
  44. if (data.status == -1) {
  45. return;
  46. }
  47. if (action.name === 'reportedcontent/delete') {
  48. $li.slideUp();
  49. } else {
  50. $clicked.fadeOut();
  51. $li.find('.reported-content-active')
  52. .removeClass('reported-content-active')
  53. .addClass('reported-content-archived');
  54. }
  55. if (!$('.reported-content-refresh').length) {
  56. $li.parent().after('<p class="reported-content-refresh mtm ptm elgg-divide-top center">' +
  57. '<a href="">' + elgg.echo('reportedcontent:refresh') + '</a></p>');
  58. }
  59. }
  60. });
  61. return false;
  62. })
  63. });