mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
@@ -2,25 +2,24 @@ import _ from 'lodash';
|
|||||||
|
|
||||||
// From server pass task.toObject() not the task document directly
|
// From server pass task.toObject() not the task document directly
|
||||||
module.exports = function updateTask (task, req = {}) {
|
module.exports = function updateTask (task, req = {}) {
|
||||||
|
let body = req.body || {};
|
||||||
|
|
||||||
// If reminders are updated -> replace the original ones
|
// If reminders are updated -> replace the original ones
|
||||||
if (req.body.reminders) {
|
if (body.reminders) {
|
||||||
task.reminders = req.body.reminders;
|
task.reminders = body.reminders;
|
||||||
delete req.body.reminders;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If checklist is updated -> replace the original one
|
// If checklist is updated -> replace the original one
|
||||||
if (req.body.checklist) {
|
if (body.checklist) {
|
||||||
task.checklist = req.body.checklist;
|
task.checklist = body.checklist;
|
||||||
delete req.body.checklist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If tags are updated -> replace the original ones
|
// If tags are updated -> replace the original ones
|
||||||
if (req.body.tags) {
|
if (body.tags) {
|
||||||
task.tags = req.body.tags;
|
task.tags = body.tags;
|
||||||
delete req.body.tags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_.merge(task, _.omit(req.body, ['_id', 'id', 'type']));
|
_.merge(task, _.omit(body, ['_id', 'id', 'type', 'reminders', 'checklist', 'tags']));
|
||||||
|
|
||||||
return [task];
|
return [task];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -100,8 +100,11 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.saveTask = function(task, stayOpen, isSaveAndClose) {
|
$scope.saveTask = function(task, stayOpen, isSaveAndClose) {
|
||||||
if (task.checklist)
|
if (task.checklist) {
|
||||||
task.checklist = _.filter(task.checklist,function(i){return !!i.text});
|
task.checklist = _.filter(task.checklist, function (i) {
|
||||||
|
return !!i.text
|
||||||
|
});
|
||||||
|
}
|
||||||
User.updateTask(task, {body: task});
|
User.updateTask(task, {body: task});
|
||||||
if (!stayOpen) task._editing = false;
|
if (!stayOpen) task._editing = false;
|
||||||
|
|
||||||
@@ -172,8 +175,8 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
if (!task.checklist[$index].text) {
|
if (!task.checklist[$index].text) {
|
||||||
// Don't allow creation of an empty checklist item
|
// Don't allow creation of an empty checklist item
|
||||||
// TODO Provide UI feedback that this item is still blank
|
// TODO Provide UI feedback that this item is still blank
|
||||||
} else if ($index == task.checklist.length-1){
|
} else if ($index == task.checklist.length - 1) {
|
||||||
User.updateTask({params:{id:task._id},body:task}); // don't preen the new empty item
|
Tasks.addChecklistItem(task._id, task.checklist[$index]);
|
||||||
task.checklist.push({completed:false,text:''});
|
task.checklist.push({completed:false,text:''});
|
||||||
focusChecklist(task,task.checklist.length-1);
|
focusChecklist(task,task.checklist.length-1);
|
||||||
} else {
|
} else {
|
||||||
@@ -185,12 +188,12 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
|
|||||||
$scope.removeChecklistItem = function(task, $event, $index, force){
|
$scope.removeChecklistItem = function(task, $event, $index, force){
|
||||||
// Remove item if clicked on trash icon
|
// Remove item if clicked on trash icon
|
||||||
if (force) {
|
if (force) {
|
||||||
Tasks.removeChecklistItem(task._id, task.checklist[$index]._id);
|
Tasks.removeChecklistItem(task._id, task.checklist[$index].id);
|
||||||
task.checklist.splice($index, 1);
|
task.checklist.splice($index, 1);
|
||||||
} else if (!task.checklist[$index].text) {
|
} else if (!task.checklist[$index].text) {
|
||||||
// User deleted all the text and is now wishing to delete the item
|
// User deleted all the text and is now wishing to delete the item
|
||||||
// saveTask will prune the empty item
|
// saveTask will prune the empty item
|
||||||
Tasks.removeChecklistItem(task._id, task.checklist[$index]._id);
|
Tasks.removeChecklistItem(task._id, task.checklist[$index].id);
|
||||||
// Move focus if the list is still non-empty
|
// Move focus if the list is still non-empty
|
||||||
if ($index > 0)
|
if ($index > 0)
|
||||||
focusChecklist(task, $index-1);
|
focusChecklist(task, $index-1);
|
||||||
|
|||||||
Reference in New Issue
Block a user