listHeader.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. limitToShowCardsCount() {
  15. return Meteor.user().getLimitToShowCardsCount();
  16. },
  17. showCardsCountForList(count) {
  18. return count > this.limitToShowCardsCount();
  19. },
  20. events() {
  21. return [{
  22. 'click .js-open-list-menu': Popup.open('listAction'),
  23. 'click .js-add-card' () {
  24. const listDom = document.getElementById(`js-list-${this.currentData()._id}`);
  25. const listComponent = BlazeComponent.getComponentForElement(listDom);
  26. listComponent.openForm({
  27. position: 'top',
  28. });
  29. },
  30. submit: this.editTitle,
  31. }];
  32. },
  33. }).register('listHeader');
  34. Template.listActionPopup.helpers({
  35. isWatching() {
  36. return this.findWatcher(Meteor.userId());
  37. },
  38. });
  39. Template.listActionPopup.events({
  40. 'click .js-list-subscribe' () {},
  41. 'click .js-select-cards' () {
  42. const cardIds = this.allCards().map((card) => card._id);
  43. MultiSelection.add(cardIds);
  44. Popup.close();
  45. },
  46. 'click .js-toggle-watch-list' () {
  47. const currentList = this;
  48. const level = currentList.findWatcher(Meteor.userId()) ? null : 'watching';
  49. Meteor.call('watch', 'list', currentList._id, level, (err, ret) => {
  50. if (!err && ret) Popup.close();
  51. });
  52. },
  53. 'click .js-close-list' (evt) {
  54. evt.preventDefault();
  55. this.archive();
  56. Popup.close();
  57. },
  58. 'click .js-more': Popup.open('listMore'),
  59. });
  60. Template.listMorePopup.events({
  61. 'click .js-delete': Popup.afterConfirm('listDelete', function () {
  62. Popup.close();
  63. this.allCards().map((card) => Cards.remove(card._id));
  64. Lists.remove(this._id);
  65. Utils.goBoardId(this.boardId);
  66. }),
  67. });