From eced94799b81486884fa4de33fee8d8f85d3718d Mon Sep 17 00:00:00 2001 From: yamanq Date: Fri, 12 Aug 2016 22:35:28 -0400 Subject: [PATCH] change markwork to togglework --- hourglass/server/main.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hourglass/server/main.js b/hourglass/server/main.js index 5e4c0d7..3c30422 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -216,13 +216,17 @@ Meteor.methods({ work.update({_id: input[1]}, {$set: {comments: comments}}); } }, - 'markWork': function(input) { + 'toggleWork': function(input) { var workobject = work.findOne({_id: input[0]}); var currentclass = classes.findOne({_id: workobject.class}); if (currentclass.subscribers.indexOf(Meteor.userId()) != -1 && - ["confirmations", "reports", "done"].indexOf(input[1]) != -1 && - workobject[input[1]].indexOf(Meteor.userId()) === -1) { - workobject[input[1]] = workobject[input[1]].push(Meteor.userId()); + ["confirmations", "reports", "done"].indexOf(input[1]) != -1) { + userindex = workobject[input[1]].indexOf(Meteor.userId()) + if userindex === -1 { + workobject[input[1]] = workobject[input[1]].push(Meteor.userId()); + } else { + workobject[input[1]] = workobject[input[1]].splice(userindex, 1); + } work.update({_id: input[1]}, {$set: workobject}); } },