summaryrefslogtreecommitdiffstats
path: root/client/components/cards/cardDetails.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/components/cards/cardDetails.js')
-rw-r--r--client/components/cards/cardDetails.js119
1 files changed, 37 insertions, 82 deletions
diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js
index a571e21a..79e9e311 100644
--- a/client/components/cards/cardDetails.js
+++ b/client/components/cards/cardDetails.js
@@ -412,11 +412,13 @@ Template.moveCardPopup.events({
// XXX We should *not* get the currentCard from the global state, but
// instead from a “component” state.
const card = Cards.findOne(Session.get('currentCard'));
+ const bSelect = $('.js-select-boards')[0];
+ const boardId = bSelect.options[bSelect.selectedIndex].value;
const lSelect = $('.js-select-lists')[0];
- const newListId = lSelect.options[lSelect.selectedIndex].value;
+ const listId = lSelect.options[lSelect.selectedIndex].value;
const slSelect = $('.js-select-swimlanes')[0];
- card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
- card.move(card.swimlaneId, newListId, 0);
+ const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
+ card.move(boardId, swimlaneId, listId, 0);
Popup.close();
},
});
@@ -430,6 +432,7 @@ BlazeComponent.extendComponent({
const boards = Boards.find({
archived: false,
'members.userId': Meteor.userId(),
+ _id: {$ne: Meteor.user().getTemplatesBoardId()},
}, {
sort: ['title'],
});
@@ -456,32 +459,15 @@ BlazeComponent.extendComponent({
},
}).register('boardsAndLists');
-
-function cloneCheckList(_id, checklist) {
- 'use strict';
- const checklistId = checklist._id;
- checklist.cardId = _id;
- checklist._id = null;
- const newChecklistId = Checklists.insert(checklist);
- ChecklistItems.find({checklistId}).forEach(function(item) {
- item._id = null;
- item.checklistId = newChecklistId;
- item.cardId = _id;
- ChecklistItems.insert(item);
- });
-}
-
Template.copyCardPopup.events({
'click .js-done'() {
const card = Cards.findOne(Session.get('currentCard'));
- const oldId = card._id;
- card._id = null;
const lSelect = $('.js-select-lists')[0];
- card.listId = lSelect.options[lSelect.selectedIndex].value;
+ listId = lSelect.options[lSelect.selectedIndex].value;
const slSelect = $('.js-select-swimlanes')[0];
- card.swimlaneId = slSelect.options[slSelect.selectedIndex].value;
+ const swimlaneId = slSelect.options[slSelect.selectedIndex].value;
const bSelect = $('.js-select-boards')[0];
- card.boardId = bSelect.options[bSelect.selectedIndex].value;
+ const boardId = bSelect.options[bSelect.selectedIndex].value;
const textarea = $('#copy-card-title');
const title = textarea.val().trim();
// insert new card to the bottom of new list
@@ -490,38 +476,13 @@ Template.copyCardPopup.events({
if (title) {
card.title = title;
card.coverId = '';
- const _id = Cards.insert(card);
+ const _id = card.copy(boardId, swimlaneId, listId);
// 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);
- // copy checklists
- let cursor = Checklists.find({cardId: oldId});
- cursor.forEach(function() {
- cloneCheckList(_id, arguments[0]);
- });
-
- // copy subtasks
- cursor = Cards.find({parentId: oldId});
- cursor.forEach(function() {
- 'use strict';
- const subtask = arguments[0];
- subtask.parentId = _id;
- subtask._id = null;
- /* const newSubtaskId = */ Cards.insert(subtask);
- });
-
- // copy card comments
- cursor = CardComments.find({cardId: oldId});
- cursor.forEach(function () {
- 'use strict';
- const comment = arguments[0];
- comment.cardId = _id;
- comment._id = null;
- CardComments.insert(comment);
- });
Popup.close();
}
},
@@ -558,9 +519,8 @@ Template.copyChecklistToManyCardsPopup.events({
Filter.addException(_id);
// copy checklists
- let cursor = Checklists.find({cardId: oldId});
- cursor.forEach(function() {
- cloneCheckList(_id, arguments[0]);
+ Checklists.find({cardId: oldId}).forEach((ch) => {
+ ch.copy(_id);
});
// copy subtasks
@@ -574,13 +534,8 @@ Template.copyChecklistToManyCardsPopup.events({
});
// copy card comments
- cursor = CardComments.find({cardId: oldId});
- cursor.forEach(function () {
- 'use strict';
- const comment = arguments[0];
- comment.cardId = _id;
- comment._id = null;
- CardComments.insert(comment);
+ CardComments.find({cardId: oldId}).forEach((cmt) => {
+ cmt.copy(_id);
});
}
Popup.close();
@@ -625,11 +580,14 @@ BlazeComponent.extendComponent({
BlazeComponent.extendComponent({
onCreated() {
this.currentCard = this.currentData();
+ this.parentBoard = new ReactiveVar(null);
this.parentCard = this.currentCard.parentCard();
if (this.parentCard) {
- this.parentBoard = this.parentCard.board();
+ const list = $('.js-field-parent-card');
+ list.val(this.parentCard._id);
+ this.parentBoard.set(this.parentCard.board()._id);
} else {
- this.parentBoard = null;
+ this.parentBoard.set(null);
}
},
@@ -637,6 +595,9 @@ BlazeComponent.extendComponent({
const boards = Boards.find({
archived: false,
'members.userId': Meteor.userId(),
+ _id: {
+ $ne: Meteor.user().getTemplatesBoardId(),
+ },
}, {
sort: ['title'],
});
@@ -644,8 +605,12 @@ BlazeComponent.extendComponent({
},
cards() {
- if (this.parentBoard) {
- return this.parentBoard.cards();
+ const currentId = Session.get('currentCard');
+ if (this.parentBoard.get()) {
+ return Cards.find({
+ boardId: this.parentBoard.get(),
+ _id: {$ne: currentId},
+ });
} else {
return [];
}
@@ -653,8 +618,8 @@ BlazeComponent.extendComponent({
isParentBoard() {
const board = this.currentData();
- if (this.parentBoard) {
- return board._id === this.parentBoard;
+ if (this.parentBoard.get()) {
+ return board._id === this.parentBoard.get();
}
return false;
},
@@ -668,11 +633,10 @@ BlazeComponent.extendComponent({
},
setParentCardId(cardId) {
- if (cardId === 'null') {
- cardId = null;
- this.parentCard = null;
- } else {
+ if (cardId) {
this.parentCard = Cards.findOne(cardId);
+ } else {
+ this.parentCard = null;
}
this.currentCard.setParentId(cardId);
},
@@ -709,23 +673,14 @@ BlazeComponent.extendComponent({
'change .js-field-parent-board'(evt) {
const selection = $(evt.currentTarget).val();
const list = $('.js-field-parent-card');
- list.empty();
if (selection === 'none') {
- this.parentBoard = null;
- list.prop('disabled', true);
+ this.parentBoard.set(null);
} else {
- this.parentBoard = Boards.findOne(selection);
- this.parentBoard.cards().forEach(function(card) {
- list.append(
- $('<option></option>').val(card._id).html(card.title)
- );
- });
+ subManager.subscribe('board', $(evt.currentTarget).val());
+ this.parentBoard.set(selection);
list.prop('disabled', false);
}
- list.append(
- `<option value='none' selected='selected'>${TAPi18n.__('custom-field-dropdown-none')}</option>`
- );
- this.setParentCardId('null');
+ this.setParentCardId(null);
},
'change .js-field-parent-card'(evt) {
const selection = $(evt.currentTarget).val();