activities.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. var activitiesPerPage = 20;
  2. BlazeComponent.extendComponent({
  3. template: function() {
  4. return 'activities';
  5. },
  6. onCreated: function() {
  7. var self = this;
  8. // XXX Should we use ReactiveNumber?
  9. self.page = new ReactiveVar(1);
  10. self.loadNextPageLocked = false;
  11. var sidebar = self.componentParent(); // XXX for some reason not working
  12. sidebar.callFirstWith(null, 'resetNextPeak');
  13. self.autorun(function() {
  14. var mode = self.data().mode;
  15. var capitalizedMode = Utils.capitalize(mode);
  16. var id = Session.get('current' + capitalizedMode);
  17. var limit = self.page.get() * activitiesPerPage;
  18. if (id === null)
  19. return;
  20. self.subscribe('activities', mode, id, limit, function() {
  21. self.loadNextPageLocked = false;
  22. // If the sibear peak hasn't increased, that mean that there are no more
  23. // activities, and we can stop calling new subscriptions.
  24. // XXX This is hacky! We need to know excatly and reactively how many
  25. // activities there are, we probably want to denormalize this number
  26. // dirrectly into card and board documents.
  27. var a = sidebar.callFirstWith(null, 'getNextPeak');
  28. sidebar.calculateNextPeak();
  29. var b = sidebar.callFirstWith(null, 'getNextPeak');
  30. if (a === b) {
  31. sidebar.callFirstWith(null, 'resetNextPeak');
  32. }
  33. });
  34. });
  35. },
  36. loadNextPage: function() {
  37. if (this.loadNextPageLocked === false) {
  38. this.page.set(this.page.get() + 1);
  39. this.loadNextPageLocked = true;
  40. }
  41. },
  42. boardLabel: function() {
  43. return TAPi18n.__('this-board');
  44. },
  45. cardLabel: function() {
  46. return TAPi18n.__('this-card');
  47. },
  48. cardLink: function() {
  49. var card = this.currentData().card();
  50. return Blaze.toHTML(HTML.A({
  51. href: card.absoluteUrl(),
  52. 'class': 'action-card'
  53. }, card.title));
  54. },
  55. memberLink: function() {
  56. return Blaze.toHTMLWithData(Template.memberName, {
  57. user: this.currentData().member()
  58. });
  59. },
  60. attachmentLink: function() {
  61. var attachment = this.currentData().attachment();
  62. return Blaze.toHTML(HTML.A({
  63. href: attachment.url(),
  64. 'class': 'js-open-attachment-viewer'
  65. }, attachment.name()));
  66. },
  67. events: function() {
  68. return [{
  69. // XXX We should use Popup.afterConfirmation here
  70. 'click .js-delete-comment': function() {
  71. var commentId = this.currentData().commentId;
  72. CardComments.remove(commentId);
  73. },
  74. 'submit .js-edit-comment': function(evt) {
  75. evt.preventDefault();
  76. var commentText = this.currentComponent().getValue();
  77. var commentId = Template.parentData().commentId;
  78. if ($.trim(commentText)) {
  79. CardComments.update(commentId, {
  80. $set: {
  81. text: commentText
  82. }
  83. });
  84. }
  85. }
  86. }];
  87. }
  88. }).register('activities');