listHeader.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. BlazeComponent.extendComponent({
  2. template() {
  3. return 'listHeader';
  4. },
  5. editTitle(evt) {
  6. evt.preventDefault();
  7. const form = this.componentChildren('inlinedForm')[0];
  8. const newTitle = form.getValue();
  9. if ($.trim(newTitle)) {
  10. Lists.update(this.currentData()._id, {
  11. $set: {
  12. title: newTitle,
  13. },
  14. });
  15. }
  16. },
  17. events() {
  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'() {
  26. const listDom = document.getElementById(`js-list-${this._id}`);
  27. const listComponent = BlazeComponent.getComponentForElement(listDom);
  28. listComponent.openForm({ position: 'top' });
  29. Popup.close();
  30. },
  31. 'click .js-list-subscribe'() {},
  32. 'click .js-select-cards'() {
  33. const cardIds = Cards.find(
  34. {listId: this._id},
  35. {fields: { _id: 1 }}
  36. ).map((card) => 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', () => {
  42. Cards.find({listId: this._id}).forEach((card) => {
  43. Cards.update(card._id, {
  44. $set: {
  45. archived: true,
  46. },
  47. });
  48. });
  49. Popup.close();
  50. }),
  51. 'click .js-close-list'(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'() {
  63. const fromList = Template.parentData(2).data._id;
  64. const toList = this._id;
  65. Cards.find({ listId: fromList }).forEach((card) => {
  66. Cards.update(card._id, {
  67. $set: {
  68. listId: toList,
  69. },
  70. });
  71. });
  72. Popup.close();
  73. },
  74. });