Moved clone tasks function to task service

This commit is contained in:
TheHollidayInn
2015-06-17 22:22:55 -05:00
parent e9269d332c
commit 838c912906
3 changed files with 26 additions and 22 deletions

View File

@@ -52,7 +52,7 @@
"challengedOwnedFilterHeader": "Ownership",
"challengedOwnedFilter": "Owned",
"challengedNotOwnedFilter": "Not Owned",
"challengedEitherOwnedFilter": "Either",,
"challengedEitherOwnedFilter": "Either",
"backToChallenges": "Back to all challenges",
"prizeValue": "<%= gemcount %>&nbsp;<%= gemicon %> Prize",
"clone": "Clone"

View File

@@ -49,8 +49,6 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
});
};
$scope.editTask = Tasks.editTask;
/**
* Create
*/
@@ -101,21 +99,10 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
reward: []
};
function cloneTask(taskToClone, index, array) {
var tmpTask = {};
for( var property in taskToClone ) {
if ( property !== "_id" && property !== "id" && property !== "dateCreated" ) {
tmpTask[property] = taskToClone[property];
}
}
var task = Shared.taskDefaults(tmpTask);
clonedTasks[taskToClone.type].push(task);
}
challenge.habits.forEach(cloneTask);
challenge.dailys.forEach(cloneTask);
challenge.todos.forEach(cloneTask);
challenge.rewards.forEach(cloneTask);
Tasks.cloneTasks(challenge.habits, clonedTasks);
Tasks.cloneTasks(challenge.dailys, clonedTasks);
Tasks.cloneTasks(challenge.todos, clonedTasks);
Tasks.cloneTasks(challenge.rewards, clonedTasks);
$scope.obj = $scope.newChallenge = new Challenges.Challenge({
name: challenge.name,

View File

@@ -6,10 +6,11 @@ angular
tasksFactory.$inject = [
'$rootScope',
'User'
'User',
'Shared'
];
function tasksFactory($rootScope, User) {
function tasksFactory($rootScope, User, Shared) {
function editTask(task) {
task._editing = !task._editing;
@@ -18,7 +19,23 @@ function tasksFactory($rootScope, User) {
if($rootScope.charts[task.id]) $rootScope.charts[task.id] = false;
}
function cloneTasks(tasksToClone, arrayWithClonedTasks) {
var len = tasksToClone.length;
for (var i = 0; i < len; i+=1) {
var tmpTask = {};
var task = tasksToClone[i];
for( var property in task ) {
if ( property !== "_id" && property !== "id" && property !== "dateCreated" ) {
tmpTask[property] = task[property];
}
}
var newTask = Shared.taskDefaults(tmpTask);
arrayWithClonedTasks[newTask.type].push(newTask);
}
}
return {
editTask: editTask
editTask: editTask,
cloneTasks: cloneTasks,
};
}