listHeader.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. BlazeComponent.extendComponent({
  2. template() {
  3. return 'listHeader';
  4. },
  5. editTitle(evt) {
  6. evt.preventDefault();
  7. const newTitle = this.componentChildren('inlinedForm')[0].getValue();
  8. const list = this.currentData();
  9. if ($.trim(newTitle)) {
  10. list.rename(newTitle);
  11. }
  12. },
  13. events() {
  14. return [{
  15. 'click .js-open-list-menu': Popup.open('listAction'),
  16. submit: this.editTitle,
  17. }];
  18. },
  19. }).register('listHeader');
  20. Template.listActionPopup.events({
  21. 'click .js-add-card'() {
  22. const listDom = document.getElementById(`js-list-${this._id}`);
  23. const listComponent = BlazeComponent.getComponentForElement(listDom);
  24. listComponent.openForm({ position: 'top' });
  25. Popup.close();
  26. },
  27. 'click .js-list-subscribe'() {},
  28. 'click .js-select-cards'() {
  29. const cardIds = this.allCards().map((card) => card._id);
  30. MultiSelection.add(cardIds);
  31. Popup.close();
  32. },
  33. 'click .js-import-card': Popup.open('listImportCard'),
  34. 'click .js-move-cards': Popup.open('listMoveCards'),
  35. 'click .js-archive-cards': Popup.afterConfirm('listArchiveCards', function() {
  36. this.allCards().forEach((card) => {
  37. card.archive();
  38. });
  39. Popup.close();
  40. }),
  41. 'click .js-close-list'(evt) {
  42. evt.preventDefault();
  43. this.archive();
  44. Popup.close();
  45. },
  46. });
  47. BlazeComponent.extendComponent({
  48. events() {
  49. return [{
  50. 'submit': (evt) => {
  51. evt.preventDefault();
  52. const jsonData = $(evt.currentTarget).find('textarea').val();
  53. const firstCardDom = $(`#js-list-${this.currentData()._id} .js-minicard:first`).get(0);
  54. const sortIndex = Utils.calculateIndex(null, firstCardDom).base;
  55. let trelloCard;
  56. try {
  57. trelloCard = JSON.parse(jsonData);
  58. } catch (e) {
  59. console.log(e);
  60. this.setError('error-json-malformed');
  61. return;
  62. }
  63. Meteor.call('importTrelloCard', trelloCard, this.currentData()._id, sortIndex,
  64. (error, response) => {
  65. if (error) {
  66. console.log(error);
  67. this.setError(error.error);
  68. } else {
  69. Filter.addException(response);
  70. Popup.close();
  71. }
  72. }
  73. );
  74. }
  75. },];
  76. },
  77. onCreated() {
  78. this.error = new ReactiveVar('');
  79. },
  80. setError(error) {
  81. this.error.set(error);
  82. },
  83. }).register('listImportCardPopup');
  84. Template.listMoveCardsPopup.events({
  85. 'click .js-select-list'() {
  86. const fromList = Template.parentData(2).data;
  87. const toList = this._id;
  88. fromList.allCards().forEach((card) => {
  89. card.move(toList);
  90. });
  91. Popup.close();
  92. },
  93. });