listHeader.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. Template.listImportCardPopup.events({
  48. submit(evt, template) {
  49. // 1. get the json data out of the form and parse it
  50. evt.preventDefault();
  51. const jsonData = $(evt.currentTarget).find('textarea').val();
  52. const data = JSON.parse(jsonData);
  53. // 2. map all fields for the card to create
  54. const firstCardDom = $(`#js-list-${this._id} .js-minicard:first`).get(0);
  55. sortIndex = Utils.calculateIndex(null, firstCardDom).base;
  56. const cardToCreate = {
  57. title: data.name,
  58. listId: this._id,
  59. boardId: this.boardId,
  60. userId: Meteor.userId(),
  61. sort: sortIndex,
  62. }
  63. // 3. finally, insert new card into list
  64. const _id = Cards.insert(cardToCreate);
  65. // In case the filter is active we need to add the newly inserted card in
  66. // the list of exceptions -- cards that are not filtered. Otherwise the
  67. // card will disappear instantly.
  68. // See https://github.com/wekan/wekan/issues/80
  69. Filter.addException(_id);
  70. }
  71. });
  72. Template.listMoveCardsPopup.events({
  73. 'click .js-select-list'() {
  74. const fromList = Template.parentData(2).data;
  75. const toList = this._id;
  76. fromList.allCards().forEach((card) => {
  77. card.move(toList);
  78. });
  79. Popup.close();
  80. },
  81. });