diff options
author | Andrés Manelli <andresmanelli@gmail.com> | 2019-02-23 23:07:54 +0100 |
---|---|---|
committer | Andrés Manelli <andresmanelli@gmail.com> | 2019-02-24 00:05:00 +0100 |
commit | 60be4df76e02afdf4dd62f8e03505d55c0ed119e (patch) | |
tree | 73d22fb7d30eb738ffd876762f1a20f28ce623a2 /models/lists.js | |
parent | f888cfd565b197903c24a07221f6a6a44e1b6223 (diff) | |
download | wekan-60be4df76e02afdf4dd62f8e03505d55c0ed119e.tar.gz wekan-60be4df76e02afdf4dd62f8e03505d55c0ed119e.tar.bz2 wekan-60be4df76e02afdf4dd62f8e03505d55c0ed119e.zip |
Allow swimlane creation from template
Mix lists with same name to avoid duplicates
Diffstat (limited to 'models/lists.js')
-rw-r--r-- | models/lists.js | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/models/lists.js b/models/lists.js index e2ded36e..76708ffd 100644 --- a/models/lists.js +++ b/models/lists.js @@ -139,8 +139,17 @@ Lists.allow({ Lists.helpers({ copy() { const oldId = this._id; - this._id = null; - const _id = Lists.insert(this); + let _id = null; + existingListWithSameName = Lists.findOne({ + boardId: this.boardId, + title: this.title, + }); + if (existingListWithSameName) { + _id = existingListWithSameName._id; + } else { + this._id = null; + _id = Lists.insert(this); + } // Copy all cards in list Cards.find({ @@ -213,23 +222,20 @@ Lists.mutations({ }, archive() { - Cards.find({ - listId: this._id, - archived: false, - }).forEach((card) => { - return card.archive(); - }); + if (this.isTemplateList()) { + this.cards().forEach((card) => { + return card.archive(); + }); + } return { $set: { archived: true } }; }, restore() { - cardsToRestore = Cards.find({ - listId: this._id, - archived: true, - }); - cardsToRestore.forEach((card) => { - card.restore(); - }); + if (this.isTemplateList()) { + this.allCards().forEach((card) => { + return card.restore(); + }); + } return { $set: { archived: false } }; }, |