site_notifications.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * site notifications JavaScript
  4. */
  5. ?>
  6. elgg.provide('elgg.site_notifications');
  7. elgg.site_notifications.init = function() {
  8. $('.site-notifications-delete').live('click', elgg.site_notifications.delete);
  9. $('.site-notifications-link').live('click', elgg.site_notifications.auto_delete);
  10. $('#site-notifications-toggle').live('click', elgg.site_notifications.toggle_all);
  11. };
  12. /**
  13. * Delete notification asynchronously when delete button clicked
  14. *
  15. * @param {Object} event
  16. *
  17. * @return void
  18. */
  19. elgg.site_notifications.delete = function(event) {
  20. var $item = $(this).closest('.elgg-item');
  21. $item.slideToggle('medium');
  22. elgg.action($(this).attr('href'), {
  23. success: function(json) {
  24. if (json.system_messages.error.length) {
  25. // Something went wrong, so undo the optimistic changes
  26. $item.slideToggle('medium');
  27. }
  28. },
  29. error: function() {
  30. // Something went wrong, so undo the optimistic changes
  31. $item.slideToggle('medium');
  32. }
  33. });
  34. event.preventDefault();
  35. }
  36. /**
  37. * Delete notification for this link
  38. *
  39. * @param {Object} event
  40. *
  41. * @return void
  42. */
  43. elgg.site_notifications.auto_delete = function(event) {
  44. var href = this.href;
  45. var id = this.id.replace("link", "delete");
  46. require(['elgg/spinner'], function (spinner) {
  47. elgg.action($('#' + id).prop('href'), {
  48. beforeSend: spinner.start,
  49. complete: function() {
  50. location.href = href;
  51. }
  52. });
  53. });
  54. return false;
  55. };
  56. /**
  57. * Toggle the checkboxes in the site notification listing
  58. *
  59. * @return void
  60. */
  61. elgg.site_notifications.toggle_all = function() {
  62. $('.site-notifications-container input[type=checkbox]').click();
  63. };
  64. elgg.register_hook_handler('init', 'system', elgg.site_notifications.init);