mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
fix(client): Allow bulk task adding in challenges
closes #6781 fixes #6723
This commit is contained in:
@@ -257,28 +257,42 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
//------------------------------------------------------------
|
||||
// Tasks
|
||||
//------------------------------------------------------------
|
||||
function addTask (addTo, listDef, challenge) {
|
||||
var task = Shared.taskDefaults({text: listDef.newTask, type: listDef.type});
|
||||
//If the challenge has not been created, we bulk add tasks on save
|
||||
if (challenge._id) Tasks.createChallengeTasks(challenge._id, task);
|
||||
if (!challenge[task.type + 's']) challenge[task.type + 's'] = [];
|
||||
challenge[task.type + 's'].unshift(task);
|
||||
delete listDef.newTask;
|
||||
function addChallengeTasks (listDef, challenge, tasks) {
|
||||
var type = listDef.type;
|
||||
|
||||
// If the challenge has not been created, we bulk add tasks on save
|
||||
tasks = tasks.map(function (task) {
|
||||
return Shared.taskDefaults({
|
||||
text: task,
|
||||
type: type,
|
||||
});
|
||||
});
|
||||
|
||||
type = type + 's';
|
||||
|
||||
if (challenge._id) {
|
||||
Tasks.createChallengeTasks(challenge._id, tasks).then(function (res) {
|
||||
addToList(challenge, type, res.data.data);
|
||||
});
|
||||
} else {
|
||||
addToList(challenge, type, tasks);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.addTask = function(addTo, listDef, challenge) {
|
||||
if (listDef.bulk) {
|
||||
var tasks = listDef.newTask.split(/[\n\r]+/);
|
||||
//Reverse the order of tasks so the tasks will appear in the order the user entered them
|
||||
tasks.reverse();
|
||||
_.each(tasks, function(t) {
|
||||
listDef.newTask = t;
|
||||
addTask(addTo, listDef, challenge);
|
||||
});
|
||||
listDef.bulk = false;
|
||||
} else {
|
||||
addTask(addTo, listDef, challenge);
|
||||
function addToList (challenge, type, tasks) {
|
||||
if (!_.isArray(tasks)) {
|
||||
tasks = [tasks];
|
||||
}
|
||||
if (!challenge[type]) {
|
||||
challenge[type] = [];
|
||||
}
|
||||
challenge[type].unshift.apply(challenge[type], tasks);
|
||||
}
|
||||
|
||||
$scope.addTask = function(listDef, challenge) {
|
||||
Tasks.addTasks(listDef, function (listDef, tasks) {
|
||||
addChallengeTasks(listDef, challenge, tasks);
|
||||
});
|
||||
}
|
||||
|
||||
$scope.removeTask = function(task, challenge) {
|
||||
@@ -294,13 +308,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User',
|
||||
task._editing = false;
|
||||
}
|
||||
|
||||
$scope.toggleBulk = function(list) {
|
||||
if (typeof list.bulk === 'undefined') {
|
||||
list.bulk = false;
|
||||
}
|
||||
list.bulk = !list.bulk;
|
||||
list.focus = true;
|
||||
};
|
||||
$scope.toggleBulk = Tasks.toggleBulk;
|
||||
|
||||
/*
|
||||
--------------------------
|
||||
|
||||
Reference in New Issue
Block a user