2
0

subtasks.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. BlazeComponent.extendComponent({
  2. addSubtask(event) {
  3. event.preventDefault();
  4. const textarea = this.find('textarea.js-add-subtask-item');
  5. const title = textarea.value.trim();
  6. const cardId = this.currentData().cardId;
  7. const card = Cards.findOne(cardId);
  8. const sortIndex = -1;
  9. const crtBoard = Boards.findOne(card.boardId);
  10. const targetBoard = crtBoard.getDefaultSubtasksBoard();
  11. const listId = targetBoard.getDefaultSubtasksListId();
  12. //Get the full swimlane data for the parent task.
  13. const parentSwimlane = Swimlanes.findOne({
  14. boardId: crtBoard._id,
  15. _id: card.swimlaneId,
  16. });
  17. //find the swimlane of the same name in the target board.
  18. const targetSwimlane = Swimlanes.findOne({
  19. boardId: targetBoard._id,
  20. title: parentSwimlane.title,
  21. });
  22. //If no swimlane with a matching title exists in the target board, fall back to the default swimlane.
  23. const swimlaneId =
  24. targetSwimlane === undefined
  25. ? targetBoard.getDefaultSwimline()._id
  26. : targetSwimlane._id;
  27. const nextCardNumber = targetBoard.getNextCardNumber();
  28. if (title) {
  29. const _id = Cards.insert({
  30. title,
  31. parentId: cardId,
  32. members: [],
  33. labelIds: [],
  34. customFields: [],
  35. listId,
  36. boardId: targetBoard._id,
  37. sort: sortIndex,
  38. swimlaneId,
  39. type: 'cardType-card',
  40. cardNumber: nextCardNumber
  41. });
  42. // In case the filter is active we need to add the newly inserted card in
  43. // the list of exceptions -- cards that are not filtered. Otherwise the
  44. // card will disappear instantly.
  45. // See https://github.com/wekan/wekan/issues/80
  46. Filter.addException(_id);
  47. setTimeout(() => {
  48. this.$('.add-subtask-item')
  49. .last()
  50. .click();
  51. }, 100);
  52. }
  53. textarea.value = '';
  54. textarea.focus();
  55. },
  56. deleteSubtask() {
  57. const subtask = this.currentData().subtask;
  58. if (subtask && subtask._id) {
  59. subtask.archive();
  60. }
  61. },
  62. editSubtask(event) {
  63. event.preventDefault();
  64. const textarea = this.find('textarea.js-edit-subtask-item');
  65. const title = textarea.value.trim();
  66. const subtask = this.currentData().subtask;
  67. subtask.setTitle(title);
  68. },
  69. pressKey(event) {
  70. //If user press enter key inside a form, submit it
  71. //Unless the user is also holding down the 'shift' key
  72. if (event.keyCode === 13 && !event.shiftKey) {
  73. event.preventDefault();
  74. const $form = $(event.currentTarget).closest('form');
  75. $form.find('button[type=submit]').click();
  76. }
  77. },
  78. events() {
  79. return [
  80. {
  81. 'click .js-open-subtask-details-menu': Popup.open('subtaskActions'),
  82. 'submit .js-add-subtask': this.addSubtask,
  83. 'submit .js-edit-subtask-title': this.editSubtask,
  84. 'click .js-delete-subtask-item': this.deleteSubtask,
  85. keydown: this.pressKey,
  86. },
  87. ];
  88. },
  89. }).register('subtasks');
  90. BlazeComponent.extendComponent({
  91. // ...
  92. }).register('subtaskItemDetail');
  93. BlazeComponent.extendComponent({
  94. events() {
  95. return [
  96. {
  97. 'click .js-view-subtask'(event) {
  98. if ($(event.target).hasClass('js-view-subtask')) {
  99. const subtask = this.currentData().subtask;
  100. const board = subtask.board();
  101. FlowRouter.go('card', {
  102. boardId: board._id,
  103. slug: board.slug,
  104. cardId: subtask._id,
  105. });
  106. }
  107. },
  108. 'click .js-delete-subtask' : Popup.afterConfirm('subtaskDelete', function () {
  109. Popup.back(2);
  110. const subtask = this.subtask;
  111. if (subtask && subtask._id) {
  112. subtask.archive();
  113. }
  114. }),
  115. }
  116. ]
  117. }
  118. }).register('subtaskActionsPopup');