diff --git a/public/css/tasks.styl b/public/css/tasks.styl index c4eae6ebef..602d4ff42b 100644 --- a/public/css/tasks.styl +++ b/public/css/tasks.styl @@ -473,6 +473,6 @@ form [type="checkbox"] margin: 0px 10px 3px 0px - width: 5% + width: 4% li:hover .checklist-icons opacity:1 \ No newline at end of file diff --git a/public/js/controllers/tasksCtrl.js b/public/js/controllers/tasksCtrl.js index d764c63117..577850d20b 100644 --- a/public/js/controllers/tasksCtrl.js +++ b/public/js/controllers/tasksCtrl.js @@ -142,6 +142,11 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N $event.preventDefault(); } } + $scope.swapChecklistItems = function(task, oldIndex, newIndex) { + var toSwap = task.checklist.splice(oldIndex, 1)[0]; + task.checklist.splice(newIndex, 0, toSwap); + $scope.saveTask(task, true); + } $scope.navigateChecklist = function(task,$index,$event){ focusChecklist(task, $event.keyCode == '40' ? $index+1 : $index-1); } diff --git a/public/js/directives/directives.js b/public/js/directives/directives.js index 14e3cf1dfd..0daf153b1a 100644 --- a/public/js/directives/directives.js +++ b/public/js/directives/directives.js @@ -118,6 +118,24 @@ habitrpg.directive('hrpgSortTasks', ['User', function(User) { } }]); +habitrpg.directive('hrpgSortChecklist', ['User', function(User) { + return function($scope, element, attrs, ngModel) { + $(element).sortable({ + axis: "y", + distance: 5, + start: function (event, ui) { + ui.item.data('startIndex', ui.item.index()); + }, + stop: function (event, ui) { + var task = angular.element(ui.item[0]).scope().task, + startIndex = ui.item.data('startIndex'); + //$scope.saveTask(task, true); + $scope.swapChecklistItems(task, startIndex, ui.item.index()); + } + }); + } +}]); + habitrpg.directive('hrpgSortTags', ['User', function(User) { return function($scope, element, attrs, ngModel) { $(element).sortable({ diff --git a/views/shared/tasks/task.jade b/views/shared/tasks/task.jade index 879a9a2ccd..a16b488f61 100644 --- a/views/shared/tasks/task.jade +++ b/views/shared/tasks/task.jade @@ -132,10 +132,12 @@ li(bindonce='list', bo-id='"task-"+task.id', ng-repeat='task in obj[list.type+"s fieldset.option-group.task-checklist(ng-if='!$state.includes("options.social.challenges")') legend.option-title span.hint(popover=env.t('checklistText'),popover-trigger='mouseenter',popover-placement='bottom')=env.t('checklist') - ul.list-unstyled - li(ng-repeat='item in task.checklist') + ul(hrpg-sort-checklist).list-unstyled + li(ng-repeat='item in task.checklist') a.pull-right.checklist-icons(ng-click='removeChecklistItem(task,$event,$index,true)') span.glyphicon.glyphicon-trash(tooltip=env.t('delete')) + span.checklist-icons.glyphicon.glyphicon-resize-vertical() + |   input(type='checkbox',ng-model='item.completed',ng-change='saveTask(task,true)') //-,ng-blur='saveTask(task,true)') input.inline-edit(type='text',ng-model='item.text',ui-keydown="{'8 46':'removeChecklistItem(task,$event,$index)'}",ui-keyup="{'13':'addChecklistItem(task,$event,$index)','38 40':'navigateChecklist(task,$index,$event)'}")