Fixed task clone functionality and updated code organization/semantics

This commit is contained in:
TheHollidayInn
2015-06-15 19:46:28 -05:00
parent 9ed3fbf613
commit b81024bdd6
3 changed files with 65 additions and 31 deletions

View File

@@ -101,9 +101,15 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
reward: []
};
function cloneTask(element, index, array) {
var task = Shared.taskDefaults(element);
clonedTasks[element.type].push(task);
function cloneTask(taskToClone, index, array) {
var tmpTask = {};
for( var property in taskToClone ) {
if ( property !== "_id" && property !== "id" ) {
tmpTask[property] = taskToClone[property];
}
}
var task = Shared.taskDefaults(tmpTask);
clonedTasks[taskToClone.type].push(task);
}
challenge.habits.forEach(cloneTask);
@@ -111,8 +117,6 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
challenge.todos.forEach(cloneTask);
challenge.rewards.forEach(cloneTask);
//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.
$scope.obj = $scope.newChallenge = new Challenges.Challenge({
name: challenge.name,
shortName: challenge.shortName,
@@ -125,7 +129,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
group: challenge.group._id,
timestamp: +(new Date),
members: [],
official: false,
official: challenge.official,
prize: challenge.prize
});
};