From 6cc1d1146e1600f20c17c153334fe397dc8ddb4f Mon Sep 17 00:00:00 2001 From: Alice Harris Date: Tue, 9 Sep 2014 17:04:13 +1000 Subject: [PATCH] refactor User.user.ops.sortTask into $scope.pushTask --- public/js/controllers/tasksCtrl.js | 8 ++++++++ views/shared/tasks/task.jade | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/public/js/controllers/tasksCtrl.js b/public/js/controllers/tasksCtrl.js index 13d9d26b14..7a5ad38d80 100644 --- a/public/js/controllers/tasksCtrl.js +++ b/public/js/controllers/tasksCtrl.js @@ -40,6 +40,14 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N */ $scope.clearDoneTodos = function() {}; + /** + * Pushes task to top or bottom of list + */ + $scope.pushTask = function(task, index, location) { + var to = (location === 'bottom') ? -1 : 0; + User.user.ops.sortTask({params:{id:task.id},query:{from:index, to:to}}) + }; + /** * This is calculated post-change, so task.completed=true if they just checked it */ diff --git a/views/shared/tasks/task.jade b/views/shared/tasks/task.jade index 91c6dbaae0..c1846e4737 100644 --- a/views/shared/tasks/task.jade +++ b/views/shared/tasks/task.jade @@ -14,10 +14,11 @@ li(bindonce='list', bo-id='"task-"+task.id', ng-repeat='task in obj[list.type+"s // Icons only available if you own the tasks (aka, hidden from challenge stats) span(ng-if='!obj._locked') - a(ng-click='User.user.ops.sortTask({params:{id:task.id},query:{from:$index, to:0}})', tooltip=env.t('pushTaskToTop')) + a(ng-click='pushTask(task,$index,"top")', tooltip=env.t('pushTaskToTop')) span.glyphicon.glyphicon-open - a(ng-click='User.user.ops.sortTask({params:{id:task.id},query:{from:$index, to:-1}})', tooltip=env.t('pushTaskToBottom')) + a(ng-click='pushTask(task,$index,"bottom")', tooltip=env.t('pushTaskToBottom')) span.glyphicon.glyphicon-import + // glyphicon-import or glyphicon-save or glyphicon-sort-by-attributes a.badge(ng-if='task.checklist[0]', ng-class='{"badge-success":checklistCompletion(task.checklist) == task.checklist.length}', ng-click='collapseChecklist(task)', tooltip=env.t('expandCollapse')) {{checklistCompletion(task.checklist)}}/{{task.checklist.length}} span.glyphicon.glyphicon-tags(tooltip='{{Shared.appliedTags(user.tags, task.tags)}}', ng-hide='Shared.noTags(task.tags)') @@ -72,7 +73,7 @@ li(bindonce='list', bo-id='"task-"+task.id', ng-repeat='task in obj[list.type+"s // Daily & Todos span.task-checker.action-yesno(bo-if='task.type=="daily" || task.type=="todo"') - input.visuallyhidden.focusable(ng-if='$state.includes("tasks")', id='box-{{obj._id}}_{{task.id}}', type='checkbox', ng-model='task.completed', ng-change='User.user.ops.sortTask({params:{id:task.id},query:{from:$index, to:-1}}); changeCheck(task)') + input.visuallyhidden.focusable(ng-if='$state.includes("tasks")', id='box-{{obj._id}}_{{task.id}}', type='checkbox', ng-model='task.completed', ng-change='pushTask(task,$index,"bottom"); changeCheck(task)') input.visuallyhidden.focusable(ng-if='!$state.includes("tasks")', id='box-{{obj._id}}_{{task.id}}', type='checkbox') label(for='box-{{obj._id}}_{{task.id}}')