Clone gems, all task info, and spacing.

This commit is contained in:
TheHollidayInn
2015-06-14 19:23:21 -05:00
parent c3307dd684
commit 9ed3fbf613

View File

@@ -93,40 +93,41 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
* Clone * Clone
*/ */
$scope.clone = function(challenge) { $scope.clone = function(challenge) {
//We need to clone habits, dailys, todos, and rewards. They each need a new id and entry in the database //We need to clone habits, dailys, todos, and rewards. They each need a new id and entry in the database
var clonedTasks = { var clonedTasks = {
habit: [], habit: [],
daily: [], daily: [],
todo: [], todo: [],
reward: [] reward: []
}; };
function cloneTask(element, index, array) { function cloneTask(element, index, array) {
var task = Shared.taskDefaults({text: element.text, type: element.type}); var task = Shared.taskDefaults(element);
clonedTasks[element.type].push(task); clonedTasks[element.type].push(task);
} }
challenge.habits.forEach(cloneTask); challenge.habits.forEach(cloneTask);
challenge.dailys.forEach(cloneTask); challenge.dailys.forEach(cloneTask);
challenge.todos.forEach(cloneTask); challenge.todos.forEach(cloneTask);
challenge.rewards.forEach(cloneTask); challenge.rewards.forEach(cloneTask);
//Use values from inc challenge. The reasons we don't use the whole challenge object is because //Use values from inc challenge. The reasons we don't use the whole challenge object is because
//Values like timestamp and memebers shouldn't be copied. //Values like timestamp and memebers shouldn't be copied.
$scope.obj = $scope.newChallenge = new Challenges.Challenge({ $scope.obj = $scope.newChallenge = new Challenges.Challenge({
name: challenge.name, name: challenge.name,
shortName: challenge.shortName, shortName: challenge.shortName,
description: challenge.description, description: challenge.description,
habits: clonedTasks.habit, habits: clonedTasks.habit,
dailys: clonedTasks.daily, dailys: clonedTasks.daily,
todos: clonedTasks.todo, todos: clonedTasks.todo,
rewards: clonedTasks.reward, rewards: clonedTasks.reward,
leader: User.user._id, leader: User.user._id,
group: challenge.group._id, group: challenge.group._id,
timestamp: +(new Date), timestamp: +(new Date),
members: [], members: [],
official: false official: false,
}); prize: challenge.prize
});
}; };
/** /**