listHeader.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. BlazeComponent.extendComponent({
  2. editTitle(evt) {
  3. evt.preventDefault();
  4. const newTitle = this.childComponents('inlinedForm')[0].getValue().trim();
  5. const list = this.currentData();
  6. if (newTitle) {
  7. list.rename(newTitle.trim());
  8. }
  9. },
  10. isWatching() {
  11. const list = this.currentData();
  12. return list.findWatcher(Meteor.userId());
  13. },
  14. events() {
  15. return [{
  16. 'click .js-open-list-menu': Popup.open('listAction'),
  17. submit: this.editTitle,
  18. }];
  19. },
  20. }).register('listHeader');
  21. Template.listActionPopup.helpers({
  22. isWatching() {
  23. return this.findWatcher(Meteor.userId());
  24. },
  25. });
  26. Template.listActionPopup.events({
  27. 'click .js-add-card'() {
  28. const listDom = document.getElementById(`js-list-${this._id}`);
  29. const listComponent = BlazeComponent.getComponentForElement(listDom);
  30. listComponent.openForm({ position: 'top' });
  31. Popup.close();
  32. },
  33. 'click .js-list-subscribe'() {},
  34. 'click .js-select-cards'() {
  35. const cardIds = this.allCards().map((card) => card._id);
  36. MultiSelection.add(cardIds);
  37. Popup.close();
  38. },
  39. 'click .js-toggle-watch-list'() {
  40. const currentList = this;
  41. const level = currentList.findWatcher(Meteor.userId()) ? null : 'watching';
  42. Meteor.call('watch', 'list', currentList._id, level, (err, ret) => {
  43. if (!err && ret) Popup.close();
  44. });
  45. },
  46. 'click .js-close-list'(evt) {
  47. evt.preventDefault();
  48. this.archive();
  49. Popup.close();
  50. },
  51. 'click .js-remove-list'(evt) {
  52. const currentList = this;
  53. evt.preventDefault();
  54. Lists.remove(currentList._id);
  55. },
  56. });