wekan/client/components/cards/subtasks.js

130 lines
3.7 KiB
JavaScript
Raw Normal View History

2018-06-18 23:25:56 +03:00
BlazeComponent.extendComponent({
addSubtask(event) {
event.preventDefault();
const textarea = this.find('textarea.js-add-subtask-item');
const title = textarea.value.trim();
const cardId = this.currentData().cardId;
const card = Cards.findOne(cardId);
2018-06-23 23:22:38 +03:00
const sortIndex = -1;
const crtBoard = Boards.findOne(card.boardId);
const targetBoard = crtBoard.getDefaultSubtasksBoard();
const listId = targetBoard.getDefaultSubtasksListId();
//Get the full swimlane data for the parent task.
const parentSwimlane = Swimlanes.findOne({
boardId: crtBoard._id,
_id: card.swimlaneId,
});
//find the swimlane of the same name in the target board.
const targetSwimlane = Swimlanes.findOne({
boardId: targetBoard._id,
title: parentSwimlane.title,
});
//If no swimlane with a matching title exists in the target board, fall back to the default swimlane.
const swimlaneId =
targetSwimlane === undefined
? targetBoard.getDefaultSwimline()._id
: targetSwimlane._id;
2018-06-18 23:25:56 +03:00
2021-08-27 21:16:27 +02:00
const nextCardNumber = targetBoard.getNextCardNumber();
2018-06-18 23:25:56 +03:00
if (title) {
2018-06-23 23:22:38 +03:00
const _id = Cards.insert({
2018-06-18 23:25:56 +03:00
title,
2018-06-23 23:22:38 +03:00
parentId: cardId,
members: [],
labelIds: [],
customFields: [],
listId,
boardId: targetBoard._id,
sort: sortIndex,
swimlaneId,
2018-08-11 00:50:20 +02:00
type: 'cardType-card',
2021-08-27 21:16:27 +02:00
cardNumber: nextCardNumber
2018-06-18 23:25:56 +03:00
});
2018-06-25 23:12:20 +03:00
2018-06-23 23:22:38 +03:00
// In case the filter is active we need to add the newly inserted card in
// the list of exceptions -- cards that are not filtered. Otherwise the
// card will disappear instantly.
// See https://github.com/wekan/wekan/issues/80
Filter.addException(_id);
2018-06-18 23:25:56 +03:00
setTimeout(() => {
2019-06-28 12:52:09 -05:00
this.$('.add-subtask-item')
.last()
.click();
2018-06-18 23:25:56 +03:00
}, 100);
}
textarea.value = '';
textarea.focus();
},
deleteSubtask() {
const subtask = this.currentData().subtask;
if (subtask && subtask._id) {
subtask.archive();
2018-06-18 23:25:56 +03:00
}
},
editSubtask(event) {
event.preventDefault();
const textarea = this.find('textarea.js-edit-subtask-item');
2018-06-18 23:25:56 +03:00
const title = textarea.value.trim();
const subtask = this.currentData().subtask;
subtask.setTitle(title);
2018-06-18 23:25:56 +03:00
},
pressKey(event) {
//If user press enter key inside a form, submit it
//Unless the user is also holding down the 'shift' key
if (event.keyCode === 13 && !event.shiftKey) {
event.preventDefault();
const $form = $(event.currentTarget).closest('form');
$form.find('button[type=submit]').click();
}
},
events() {
2019-06-28 12:52:09 -05:00
return [
{
'click .js-open-subtask-details-menu': Popup.open('subtaskActions'),
2019-06-28 12:52:09 -05:00
'submit .js-add-subtask': this.addSubtask,
'submit .js-edit-subtask-title': this.editSubtask,
'click .js-delete-subtask-item': this.deleteSubtask,
2019-06-28 12:52:09 -05:00
keydown: this.pressKey,
},
];
2018-06-18 23:25:56 +03:00
},
}).register('subtasks');
BlazeComponent.extendComponent({
// ...
2018-06-18 23:25:56 +03:00
}).register('subtaskItemDetail');
BlazeComponent.extendComponent({
events() {
return [
{
'click .js-view-subtask'(event) {
if ($(event.target).hasClass('js-view-subtask')) {
const subtask = this.currentData().subtask;
const board = subtask.board();
FlowRouter.go('card', {
boardId: board._id,
slug: board.slug,
cardId: subtask._id,
});
}
},
'click .js-delete-subtask' : Popup.afterConfirm('subtaskDelete', function () {
Popup.back(2);
const subtask = this.subtask;
if (subtask && subtask._id) {
subtask.archive();
}
}),
}
]
}
}).register('subtaskActionsPopup');