listHeader.js 3.8 KB

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