listHeader.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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) {
  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. const 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. map labels
  65. data.labels.forEach((current) => {
  66. const color = current.color;
  67. const name = current.name;
  68. const existingLabel = this.board().getLabel(name, color);
  69. let labelId = undefined;
  70. if (existingLabel) {
  71. labelId = existingLabel._id;
  72. } else {
  73. let labelCreated = this.board().addLabel(name, color);
  74. // XXX currently mutations return no value so we have to fetch the label we just created
  75. // waiting on https://github.com/mquandalle/meteor-collection-mutations/issues/1 to remove...
  76. labelCreated = this.board().getLabel(name, color);
  77. labelId = labelCreated._id;
  78. }
  79. if(labelId) {
  80. if (!cardToCreate.labelIds) {
  81. cardToCreate.labelIds = [];
  82. }
  83. cardToCreate.labelIds.push(labelId);
  84. }
  85. });
  86. // 4. insert new card into list
  87. const _id = Cards.insert(cardToCreate);
  88. // 5. parse actions and add comments
  89. data.actions.forEach((current) => {
  90. if(current.type === 'commentCard') {
  91. const commentToCreate = {
  92. boardId: this.boardId,
  93. cardId: _id,
  94. userId: Meteor.userId(),
  95. text: current.data.text,
  96. };
  97. CardComments.insert(commentToCreate);
  98. }
  99. // XXX add other type of activities?
  100. Popup.close();
  101. });
  102. // In case the filter is active we need to add the newly inserted card in
  103. // the list of exceptions -- cards that are not filtered. Otherwise the
  104. // card will disappear instantly.
  105. // See https://github.com/wekan/wekan/issues/80
  106. Filter.addException(_id);
  107. },
  108. });
  109. Template.listMoveCardsPopup.events({
  110. 'click .js-select-list'() {
  111. const fromList = Template.parentData(2).data;
  112. const toList = this._id;
  113. fromList.allCards().forEach((card) => {
  114. card.move(toList);
  115. });
  116. Popup.close();
  117. },
  118. });