Cleanup add checklist item function

Cleaned up `addChecklistItem` function, shortening it
This commit is contained in:
Lucas Torroba (@zesme)
2016-05-26 18:51:43 -03:00
parent 46be1553f0
commit b20f5545b9

View File

@@ -189,16 +189,13 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
} }
$scope.addChecklistItem = function(task, $event, $index) { $scope.addChecklistItem = function(task, $event, $index) {
if (!task.checklist[$index].text) { if (task.checklist[$index].text) {
// Don't allow creation of an empty checklist item
// TODO Provide UI feedback that this item is still blank
} else if ($index == task.checklist.length - 1) {
$scope.saveTask(task, true);
task.checklist.push({completed:false, text:''});
focusChecklist(task, task.checklist.length - 1);
} else {
$scope.saveTask(task, true); $scope.saveTask(task, true);
if ($index == task.checklist.length - 1)
task.checklist.push({ completed: false, text: '' });
focusChecklist(task, $index + 1); focusChecklist(task, $index + 1);
} else {
// TODO Provide UI feedback that this item is still blank
} }
} }