Files
habitica/website/client-old/js/components/groupTasks/groupTasksController.js
Keith Holliday 13df60e0dd Group approval ui (#8184)
* Added all ui components back

* Added group ui items back and initial group approval directive

* Added ability to mark tasks as requires approval. Added approvals ctrl. Added get approvals method to tasks service

* Added approval list view with approving functionality

* Added error to produce message when task requests approval

* Added notification display for group approvals

* Fixed notification read and adding task

* Fixed syncing with group approval required

* Added group id to notifications for redirect on client side

* Fixed approval request tests

* Fixed linting issues

* Removed expectation from beforeEach

* Moved string to locale

* Added eslint ignore

* Updated notification for group approved, added new icons, and updated styles

* Hid group plan ui
2016-11-12 23:47:45 +01:00

82 lines
2.5 KiB
JavaScript

habitrpg.controller('GroupTasksCtrl', ['$scope', 'Shared', 'Tasks', 'User', function ($scope, Shared, Tasks, User) {
$scope.editTask = Tasks.editTask;
$scope.toggleBulk = Tasks.toggleBulk;
$scope.cancelTaskEdit = Tasks.cancelTaskEdit;
function addTask (listDef, taskTexts) {
taskTexts.forEach(function (taskText) {
var task = Shared.taskDefaults({text: taskText, type: listDef.type});
//If the group has not been created, we bulk add tasks on save
var group = $scope.obj;
if (group._id) Tasks.createGroupTasks(group._id, task);
if (!group[task.type + 's']) group[task.type + 's'] = [];
group[task.type + 's'].unshift(task);
});
};
$scope.addTask = function(listDef) {
Tasks.addTasks(listDef, addTask);
};
$scope.removeTask = function(task, group) {
if (!Tasks.removeTask(task)) return;
//We only pass to the api if the group exists, otherwise, the tasks only exist on the client
if (group._id) Tasks.deleteTask(task._id);
var index = group[task.type + 's'].indexOf(task);
group[task.type + 's'].splice(index, 1);
};
$scope.saveTask = function(task, stayOpen, isSaveAndClose) {
Tasks.saveTask (task, stayOpen, isSaveAndClose);
Tasks.updateTask(task._id, task);
};
$scope.shouldShow = function(task, list, prefs){
return true;
};
$scope.canEdit = function(task) {
return true;
};
/*
------------------------
Tags
------------------------
*/
$scope.updateTaskTags = function (tagId, task) {
var tagIndex = task.tags.indexOf(tagId);
if (tagIndex === -1) {
Tasks.addTagToTask(task._id, tagId);
task.tags.push(tagId);
} else {
Tasks.removeTagFromTask(task._id, tagId);
task.tags.splice(tagIndex, 1);
}
};
/*
------------------------
Checklists
------------------------
*/
$scope.addChecklist = Tasks.addChecklist;
$scope.addChecklistItem = Tasks.addChecklistItemToUI;
$scope.removeChecklistItem = Tasks.removeChecklistItemFromUI;
$scope.swapChecklistItems = Tasks.swapChecklistItems;
$scope.navigateChecklist = Tasks.navigateChecklist;
$scope.checklistCompletion = Tasks.checklistCompletion;
$scope.collapseChecklist = function (task) {
Tasks.collapseChecklist(task);
//@TODO: Currently the api save of the task is separate, so whenever we need to save the task we need to call the respective api
Tasks.updateTask(task._id, task);
};
}]);