listHeader.js 2.9 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. 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. description: data.desc,
  59. listId: this._id,
  60. boardId: this.boardId,
  61. userId: Meteor.userId(),
  62. sort: sortIndex,
  63. }
  64. // 3. insert new card into list
  65. const _id = Cards.insert(cardToCreate);
  66. // 4. parse actions and add comments/activities - if any
  67. data.actions.forEach((current, i, actions)=>{
  68. if(current.type == 'commentCard') {
  69. const commentToCreate = {
  70. boardId: this.boardId,
  71. cardId: _id,
  72. userId: Meteor.userId(),
  73. text: current.data.text
  74. }
  75. CardComments.insert(commentToCreate);
  76. }
  77. Popup.close();
  78. });
  79. // In case the filter is active we need to add the newly inserted card in
  80. // the list of exceptions -- cards that are not filtered. Otherwise the
  81. // card will disappear instantly.
  82. // See https://github.com/wekan/wekan/issues/80
  83. Filter.addException(_id);
  84. }
  85. });
  86. Template.listMoveCardsPopup.events({
  87. 'click .js-select-list'() {
  88. const fromList = Template.parentData(2).data;
  89. const toList = this._id;
  90. fromList.allCards().forEach((card) => {
  91. card.move(toList);
  92. });
  93. Popup.close();
  94. },
  95. });