diff --git a/bower.json b/bower.json index 3e898dea40..3a1b4d65cc 100644 --- a/bower.json +++ b/bower.json @@ -21,7 +21,6 @@ "angular-sanitize": "~1.2.1", "angular-resource": "~1.2.1", "angular-ui": "~0.4.0", - "angular-ui-utils": "~0.0.4", "angular-bootstrap": "~0.5.0", "angular-ui-router": "ca3b4777a603df8f86cfd653c8f6c38b2ae05d89", "angular-loading-bar": "~0.0.5", @@ -38,13 +37,14 @@ "js-emoji": "git://github.com/snicker/js-emoji#master", "gemoji": "git://github.com/github/gemoji", "sticky": "*", - "bootstrap-tour": "~0.8.0" + "bootstrap-tour": "~0.8.0", + "angular-ui-utils": "~0.1.0" }, "resolutions": { "jquery": "~2.0.3", "bootstrap": "v2.3.2", "angular": "~1.2.1", - "bootstrap-tour": "~0.8.0" + "angular-ui-utils": "~0.1.0" }, "devDependencies": { "angular-mocks": "~1.2.1" diff --git a/public/js/controllers/tasksCtrl.js b/public/js/controllers/tasksCtrl.js index c373a6e53f..ba262a1533 100644 --- a/public/js/controllers/tasksCtrl.js +++ b/public/js/controllers/tasksCtrl.js @@ -82,29 +82,32 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N Checklists ------------------------ */ - var ws = window.setTimeout; + function focusChecklist(task,index) { + window.setTimeout(function(){ + $('#task-'+task.id+' .checklist-form .inline-edit')[index].focus(); + }); + } $scope.addChecklist = function(task) { task.checklist = [{completed:false,text:""}]; - ws(function(){ - $('#task-'+task.id+' .checklist-form .inline-edit')[0].focus(); - }); + focusChecklist(task,0); } $scope.addChecklistItem = function(task,$event,$index) { if ($index == task.checklist.length-1){ User.user.ops.updateTask({params:{id:task.id},body:task}); // don't preen the new empty item task.checklist.push({completed:false,text:''}); - ws(function(){ - var list = $('#task-'+task.id+' .checklist-form .inline-edit'); - list[list.length-1].focus(); - },0); + focusChecklist(task,task.checklist.length-1); } else { $scope.saveTask(task,true); - $('#task-'+task.id+' .checklist-form .inline-edit')[$index+1].focus(); + focusChecklist(task,$index+1); } } - $scope.removeChecklistItem = function(task,$index){ - task.checklist.splice($index,1); - $scope.saveTask(task,true); + $scope.removeChecklistItem = function(task,$index,force){ + var backspaced = !force && !task.checklist[$index].text + if (force || backspaced) { + task.checklist.splice($index,1); + $scope.saveTask(task,true); + if (backspaced) focusChecklist(task,$index-1); + } } $scope.checklistCompletion = function(checklist){ return _.reduce(checklist,function(m,i){return m+(i.completed ? 1 : 0);},0) diff --git a/public/manifest.json b/public/manifest.json index dee320860c..6fc51a7f19 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -11,7 +11,7 @@ "bower_components/angular-ui-router/release/angular-ui-router.js", "bower_components/angular-resource/angular-resource.min.js", "bower_components/angular-ui/build/angular-ui.js", - "bower_components/angular-ui-utils/modules/keypress/keypress.js", + "bower_components/angular-ui-utils/ui-utils.min.js", "bower_components/angular-loading-bar/build/loading-bar.js", "bower_components/Angular-At-Directive/src/at.js", "bower_components/Angular-At-Directive/src/caret.js", diff --git a/views/shared/tasks/task.jade b/views/shared/tasks/task.jade index 5fd62896c8..d612175a5d 100644 --- a/views/shared/tasks/task.jade +++ b/views/shared/tasks/task.jade @@ -114,10 +114,10 @@ li(bindonce='list', bo-id='"task-"+task.id', ng-repeat='task in obj[list.type+"s legend.option-title Checklist ul.unstyled li(ng-repeat='item in task.checklist') - a.pull-right.checklist-icons(ng-click='removeChecklistItem(task,$index)') + a.pull-right.checklist-icons(ng-click='removeChecklistItem(task,$index,true)') i.icon-trash(tooltip='Delete') input(type='checkbox',ng-model='item.completed',ng-change='saveTask(task,true)') - input.inline-edit(type='text',ng-model='item.text',ui-keypress="{'13':'addChecklistItem(task,$event,$index)'}")//-,ng-blur='saveTask(task,true)') + input.inline-edit(type='text',ng-model='item.text',ui-keyup="{13:'addChecklistItem(task,$event,$index)','8 49':'removeChecklistItem(task,$index)'}")//-,ng-blur='saveTask(task,true)') form(ng-submit='saveTask(task)')