This commit is contained in:
Blade Barringer
2016-08-23 21:40:14 -05:00
parent 671e954cec
commit 3d64f2b849
13 changed files with 84 additions and 106 deletions

View File

@@ -116,16 +116,17 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
}
};
$scope.saveTask = function(task, stayOpen, isSaveAndClose) {
angular.copy(task._edit, task);
task._edit = undefined;
$scope.removeTask = function(task) {
if (!confirm(window.env.t('sureDelete', {taskType: window.env.t(task.type), taskText: task.text}))) return;
User.deleteTask({params:{id: task._id, taskType: task.type}})
};
$scope.saveTask = function(task, stayOpen, isSaveAndClose) {
if (task.checklist) {
task.checklist = _.filter(task.checklist, function (i) {
return !!i.text
});
}
User.updateTask(task, {body: task});
if (!stayOpen) task._editing = false;
@@ -136,19 +137,17 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
if (task.type == 'habit') Guide.goto('intro', 3);
};
$scope.completeChecklistItem = function completeChecklistItem(task) {
User.updateTask(task, {body: task});
};
/**
* Reset $scope.task to $scope.originalTask
*/
$scope.cancelTaskEdit = Tasks.cancelTaskEdit;
$scope.removeTask = function(task) {
if (!confirm(window.env.t('sureDelete', {taskType: window.env.t(task.type), taskText: task.text}))) return;
task._edit = undefined;
User.deleteTask({params:{id: task._id, taskType: task.type}})
$scope.cancel = function() {
var key;
for (key in $scope.task) {
$scope.task[key] = $scope.originalTask[key];
}
$scope.originalTask = null;
$scope.editedTask = null;
$scope.editing = false;
};
$scope.unlink = function(task, keep) {
@@ -211,16 +210,16 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
}
$scope.addChecklist = function(task) {
task._edit.checklist = [{completed:false, text:""}];
focusChecklist(task._edit,0);
task.checklist = [{completed:false, text:""}];
focusChecklist(task,0);
}
$scope.addChecklistItem = function(task, $event, $index) {
if (task._edit.checklist[$index].text) {
if ($index === task._edit.checklist.length - 1) {
task._edit.checklist.push({ completed: false, text: '' });
}
focusChecklist(task._edit, $index + 1);
if (task.checklist[$index].text) {
$scope.saveTask(task, true);
if ($index === task.checklist.length - 1)
task.checklist.push({ completed: false, text: '' });
focusChecklist(task, $index + 1);
} else {
// TODO Provide UI feedback that this item is still blank
}
@@ -229,21 +228,24 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
$scope.removeChecklistItem = function(task, $event, $index, force) {
// Remove item if clicked on trash icon
if (force) {
task._edit.checklist.splice($index, 1);
} else if (!task._edit.checklist[$index].text) {
if (task.checklist[$index].id) Tasks.removeChecklistItem(task._id, task.checklist[$index].id);
task.checklist.splice($index, 1);
} else if (!task.checklist[$index].text) {
// User deleted all the text and is now wishing to delete the item
// saveTask will prune the empty item
if (task.checklist[$index].id) Tasks.removeChecklistItem(task._id, task.checklist[$index].id);
// Move focus if the list is still non-empty
if ($index > 0)
focusChecklist(task._edit, $index-1);
focusChecklist(task, $index-1);
// Don't allow the backspace key to navigate back now that the field is gone
$event.preventDefault();
}
}
$scope.swapChecklistItems = function(task, oldIndex, newIndex) {
var toSwap = task._edit.checklist.splice(oldIndex, 1)[0];
task._edit.checklist.splice(newIndex, 0, toSwap);
var toSwap = task.checklist.splice(oldIndex, 1)[0];
task.checklist.splice(newIndex, 0, toSwap);
$scope.saveTask(task, true);
}
$scope.navigateChecklist = function(task,$index,$event){
@@ -347,7 +349,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
*/
$scope.updateTaskTags = function (tagId, task) {
var tagIndex = task._edit.tags.indexOf(tagId);
var tagIndex = task.tags.indexOf(tagId);
if (tagIndex === -1) {
Tasks.addTagToTask(task._id, tagId);
task.tags.push(tagId);
@@ -355,7 +357,6 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
Tasks.removeTagFromTask(task._id, tagId);
task.tags.splice(tagIndex, 1);
}
angular.copy(task.tags, task._edit.tags);
}
/*