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();
|
2020-04-02 07:49:26 +02:00
|
|
|
|
|
|
|
//Get the full swimlane data for the parent task.
|
2020-04-08 23:16:48 +03:00
|
|
|
const parentSwimlane = Swimlanes.findOne({
|
|
|
|
boardId: crtBoard._id,
|
|
|
|
_id: card.swimlaneId,
|
|
|
|
});
|
2020-04-02 07:49:26 +02:00
|
|
|
//find the swimlane of the same name in the target board.
|
2020-04-08 23:16:48 +03:00
|
|
|
const targetSwimlane = Swimlanes.findOne({
|
|
|
|
boardId: targetBoard._id,
|
|
|
|
title: parentSwimlane.title,
|
|
|
|
});
|
2020-04-02 07:49:26 +02:00
|
|
|
//If no swimlane with a matching title exists in the target board, fall back to the default swimlane.
|
2020-04-08 23:16:48 +03:00
|
|
|
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() {
|
2018-06-19 00:25:43 +03:00
|
|
|
const subtask = this.currentData().subtask;
|
|
|
|
if (subtask && subtask._id) {
|
2018-06-23 23:44:45 +03:00
|
|
|
subtask.archive();
|
2018-06-18 23:25:56 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
editSubtask(event) {
|
|
|
|
event.preventDefault();
|
2018-06-19 00:25:43 +03:00
|
|
|
const textarea = this.find('textarea.js-edit-subtask-item');
|
2018-06-18 23:25:56 +03:00
|
|
|
const title = textarea.value.trim();
|
2018-06-19 00:25:43 +03:00
|
|
|
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 [
|
|
|
|
{
|
2022-04-04 15:38:31 -03:00
|
|
|
'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,
|
2022-04-04 15:38:31 -03:00
|
|
|
'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:38:41 +03:00
|
|
|
// ...
|
2018-06-18 23:25:56 +03:00
|
|
|
}).register('subtaskItemDetail');
|
2022-04-04 15:38:31 -03:00
|
|
|
|
|
|
|
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');
|