listHeader.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. BlazeComponent.extendComponent({
  2. template: function() {
  3. return 'listHeader';
  4. },
  5. editTitle: function(evt) {
  6. evt.preventDefault();
  7. var form = this.componentChildren('inlinedForm')[0];
  8. var newTitle = form.getValue();
  9. if ($.trim(newTitle)) {
  10. Lists.update(this.currentData()._id, {
  11. $set: {
  12. title: newTitle
  13. }
  14. });
  15. }
  16. },
  17. events: function() {
  18. return [{
  19. 'click .js-open-list-menu': Popup.open('listAction'),
  20. submit: this.editTitle
  21. }];
  22. }
  23. }).register('listHeader');
  24. Template.listActionPopup.events({
  25. 'click .js-add-card': function() {
  26. var listDom = document.getElementById('js-list-' + this._id);
  27. var listComponent = BlazeComponent.getComponentForElement(listDom);
  28. listComponent.openForm({ position: 'top' });
  29. Popup.close();
  30. },
  31. 'click .js-list-subscribe': function() {},
  32. 'click .js-select-cards': function() {
  33. var cardIds = Cards.find(
  34. {listId: this._id},
  35. {fields: { _id: 1 }}
  36. ).map(function(card) { return card._id; });
  37. MultiSelection.add(cardIds);
  38. Popup.close();
  39. },
  40. 'click .js-move-cards': Popup.open('listMoveCards'),
  41. 'click .js-archive-cards': Popup.afterConfirm('listArchiveCards', function() {
  42. Cards.find({listId: this._id}).forEach(function(card) {
  43. Cards.update(card._id, {
  44. $set: {
  45. archived: true
  46. }
  47. });
  48. });
  49. Popup.close();
  50. }),
  51. 'click .js-close-list': function(evt) {
  52. evt.preventDefault();
  53. Lists.update(this._id, {
  54. $set: {
  55. archived: true
  56. }
  57. });
  58. Popup.close();
  59. }
  60. });
  61. Template.listMoveCardsPopup.events({
  62. 'click .js-select-list': function() {
  63. var fromList = Template.parentData(2).data._id;
  64. var toList = this._id;
  65. Cards.find({listId: fromList}).forEach(function(card) {
  66. Cards.update(card._id, {
  67. $set: {
  68. listId: toList
  69. }
  70. });
  71. });
  72. Popup.close();
  73. }
  74. });