/applications/dashboard/js/activity.js

https://github.com/dkobia/Garden · JavaScript · 110 lines · 81 code · 13 blank · 16 comment · 11 complexity · a1c7511148a88b363f578f4932361530 MD5 · raw file

  1. jQuery(document).ready(function($) {
  2. // Set the max chars in the activity comment boxes
  3. $('form.Activity textarea').setMaxChars(1000);
  4. // Hide activity deletes and hijack their clicks to confirm
  5. $('ul.Activities a.Delete, ul.Activities a.DeleteComment').popup({
  6. confirm: true,
  7. followConfirm: false,
  8. afterConfirm: function(json, sender) {
  9. var row = $(sender).parents('li:first');
  10. $(row).slideUp('fast', function() {
  11. $(row).remove();
  12. });
  13. }
  14. });
  15. // Reveal activity deletes on hover
  16. $('ul.Activities li').livequery(function() {
  17. $(this).find('a.Delete').hide();
  18. $(this).hover(function() {
  19. $(this).find('a.Delete').show();
  20. }, function() {
  21. $(this).find('a.Delete').hide();
  22. });
  23. });
  24. /* Comments */
  25. // Hide/reveal the comments when the comment link is clicked
  26. $('a.CommentOption').live('click', function() {
  27. var comments = $(this).parents('li.Activity').find('ul.ActivityComments');
  28. comments.toggle();
  29. comments.find('a.CommentLink').click();
  30. return false;
  31. });
  32. // Hijack commentlink clicks
  33. $('a.CommentLink').live('click', function() {
  34. // Hide the anchor
  35. var anchor = this;
  36. $(anchor).hide();
  37. var row = $(anchor).parents('li.CommentForm');
  38. // Reveal the form
  39. var frm = $(row).find('form');
  40. frm.show();
  41. // Focus on the textbox
  42. var textbox = frm.find('textarea');
  43. textbox.focus().blur(function() {
  44. // Hide the form onblur if empty
  45. if (this.value == '') {
  46. var comments = $(anchor).parents('.Comments');
  47. var children = $(comments).children();
  48. var rowCount = children.length - 1; // Subtract the commentform row
  49. if (rowCount > 0) {
  50. // Hide/clear the form and reveal the anchor
  51. $(comments).find('.Errors').remove();
  52. $(frm).hide();
  53. $(anchor).show();
  54. } else {
  55. // Hide all elements in .Comments
  56. $(comments).hide();
  57. }
  58. }
  59. });
  60. return false;
  61. });
  62. // Hijack comment form button clicks
  63. $('ul.ActivityComments form input.Button').live('click', function() {
  64. var button = this;
  65. var frm = $(button).parents('form');
  66. var row = $(frm).parents('li.CommentForm');
  67. var textbox = $(row).find('textarea');
  68. // Post the form, place the results above the input, and erase the textbox
  69. var postValues = frm.serialize() + '&DeliveryType=VIEW&DeliveryMethod=JSON'; // DELIVERY_TYPE_VIEW
  70. var activityId = frm.find('[name$=ActivityID]').val();
  71. var action = frm.attr('action');
  72. $.ajax({
  73. type: "POST",
  74. url: action,
  75. data: postValues,
  76. dataType: 'json',
  77. error: function(XMLHttpRequest, textStatus, errorThrown) {
  78. $.popup({}, XMLHttpRequest.responseText);
  79. },
  80. success: function(json) {
  81. json = $.postParseJson(json);
  82. // Remove any old errors from the form
  83. $('div.Errors').remove();
  84. if (json.FormSaved == false) {
  85. if (json.StatusMessage != null && json.StatusMessage != '')
  86. $(row).prepend(json.StatusMessage);
  87. } else {
  88. $(row).before(json.Data);
  89. textbox.val('').blur();
  90. // Make sure that hidden items appear
  91. $('ul.ActivityComments li.Hidden').slideDown('fast');
  92. }
  93. }
  94. });
  95. return false;
  96. });
  97. });