details.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. BlazeComponent.extendComponent({
  2. template: function() {
  3. return 'cardSidebar';
  4. },
  5. mixins: function() {
  6. return [Mixins.InfiniteScrolling];
  7. },
  8. calculateNextPeak: function() {
  9. var altitude = this.find('.js-card-sidebar-content').scrollHeight;
  10. this.callFirstWith(this, 'setNextPeak', altitude);
  11. },
  12. reachNextPeak: function() {
  13. var activitiesComponent = this.componentChildren('activities')[0];
  14. activitiesComponent.loadNextPage();
  15. },
  16. events: function() {
  17. return [{
  18. 'click .js-move-card': Popup.open('moveCard'),
  19. 'submit .js-card-description': function(evt) {
  20. evt.preventDefault();
  21. var cardId = Session.get('currentCard');
  22. var form = this.componentChildren('inlinedForm')[0];
  23. var newDescription = form.getValue();
  24. Cards.update(cardId, {
  25. $set: {
  26. description: newDescription
  27. }
  28. });
  29. form.close();
  30. },
  31. 'click .js-close-card-detail': function() {
  32. Utils.goBoardId(Session.get('currentBoard'));
  33. },
  34. 'click .editable .js-card-title': function(event, t) {
  35. var editable = t.$('.card-detail-title');
  36. // add class editing and focus
  37. $('.editing').removeClass('editing');
  38. editable.addClass('editing');
  39. editable.find('#title').focus();
  40. },
  41. 'click .js-edit-desc': function(event, t) {
  42. var editable = t.$('.card-detail-item');
  43. // editing remove based and add current editing.
  44. $('.editing').removeClass('editing');
  45. editable.addClass('editing');
  46. editable.find('#desc').focus();
  47. event.preventDefault();
  48. },
  49. 'click .js-cancel-edit': function(event, t) {
  50. // remove editing hide.
  51. $('.editing').removeClass('editing');
  52. },
  53. 'submit #WindowTitleEdit': function(event, t) {
  54. var title = t.find('#title').value;
  55. if ($.trim(title)) {
  56. Cards.update(this.card._id, {
  57. $set: {
  58. title: title
  59. }
  60. }, function (err, res) {
  61. if (!err) $('.editing').removeClass('editing');
  62. });
  63. }
  64. event.preventDefault();
  65. },
  66. 'submit #WindowDescEdit': function(event, t) {
  67. Cards.update(this.card._id, {
  68. $set: {
  69. description: t.find('#desc').value
  70. }
  71. }, function(err) {
  72. if (!err) $('.editing').removeClass('editing');
  73. });
  74. event.preventDefault();
  75. },
  76. 'click .member': Popup.open('cardMember'),
  77. 'click .js-details-edit-members': Popup.open('cardMembers'),
  78. 'click .js-details-edit-labels': Popup.open('cardLabels')
  79. }];
  80. }
  81. }).register('cardSidebar');
  82. Template.moveCardPopup.events({
  83. 'click .js-select-list': function() {
  84. // XXX We should *not* get the currentCard from the global state, but
  85. // instead from a “component” state.
  86. var cardId = Session.get('currentCard');
  87. var newListId = this._id;
  88. Cards.update(cardId, {
  89. $set: {
  90. listId: newListId
  91. }
  92. });
  93. }
  94. });