mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-03 04:29:40 +00:00
checklists: handle backspacing an empty CL item
This commit is contained in:
parent
ebc7cf6bcb
commit
1110338b9b
4 changed files with 21 additions and 18 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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)')
|
||||
|
|
|
|||
Loading…
Reference in a new issue