summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorAndrés Manelli <andresmanelli@gmail.com>2018-04-17 01:55:57 -0300
committerAndrés Manelli <andresmanelli@gmail.com>2018-08-10 23:59:08 +0200
commit0a62089df02b2ab308d4749a837e08c4164cb770 (patch)
tree7a8ff38e2074e3568d99f5202893d32398d6fb76 /models
parenta93de07fb9b85f97da274bf549e5244ee8e30484 (diff)
downloadwekan-0a62089df02b2ab308d4749a837e08c4164cb770.tar.gz
wekan-0a62089df02b2ab308d4749a837e08c4164cb770.tar.bz2
wekan-0a62089df02b2ab308d4749a837e08c4164cb770.zip
Allow description and member two way binding
Diffstat (limited to 'models')
-rw-r--r--models/cards.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/models/cards.js b/models/cards.js
index 4b18b8f3..de868dde 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -406,6 +406,18 @@ Cards.helpers({
return this.isImportedCard() || this.isImportedBoard();
},
+ setDescription(description) {
+ if (this.isImportedCard()) {
+ const card = Cards.findOne({_id: this.importedId});
+ return Cards.update({_id: this.importedId}, {$set: {description}});
+ } else if (this.isImportedBoard()) {
+ const board = Boards.findOne({_id: this.importedId});
+ return Boards.update({_id: this.importedId}, {$set: {description}});
+ } else {
+ return {$set: {description}};
+ }
+ },
+
getDescription() {
if (this.isImportedCard()) {
const card = Cards.findOne({_id: this.importedId});
@@ -426,6 +438,62 @@ Cards.helpers({
return null;
}
},
+
+ getMembers() {
+ if (this.isImportedCard()) {
+ const card = Cards.findOne({_id: this.importedId});
+ return card.members;
+ } else if (this.isImportedBoard()) {
+ const board = Boards.findOne({_id: this.importedId});
+ return board.activeMembers().map((member) => {
+ return member.userId;
+ });
+ } else {
+ return this.members;
+ }
+ },
+
+ assignMember(memberId) {
+ if (this.isImportedCard()) {
+ return Cards.update(
+ { _id: this.importedId },
+ { $addToSet: { members: memberId }}
+ );
+ } else if (this.isImportedBoard()) {
+ const board = Boards.findOne({_id: this.importedId});
+ return board.addMember(memberId);
+ } else {
+ return Cards.update(
+ { _id: this._id },
+ { $addToSet: { members: memberId}}
+ );
+ }
+ },
+
+ unassignMember(memberId) {
+ if (this.isImportedCard()) {
+ return Cards.update(
+ { _id: this.importedId },
+ { $pull: { members: memberId }}
+ );
+ } else if (this.isImportedBoard()) {
+ const board = Boards.findOne({_id: this.importedId});
+ return board.removeMember(memberId);
+ } else {
+ return Cards.update(
+ { _id: this._id },
+ { $pull: { members: memberId}}
+ );
+ }
+ },
+
+ toggleMember(memberId) {
+ if (this.getMembers() && this.getMembers().indexOf(memberId) > -1) {
+ return this.unassignMember(memberId);
+ } else {
+ return this.assignMember(memberId);
+ }
+ },
});
Cards.mutations({