diff --git a/src/ajax.js b/src/ajax.js index 062b23c..e36bb2e 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -35,7 +35,6 @@ function loadTasks() nocache = '&rnd='+Math.random(); $.getJSON('ajax.php?loadTasks&list='+curList.id+'&compl='+filter.compl+'&sort='+sortBy+search+tag+'&tz='+tz+nocache, function(json){ resetAjaxErrorTrigger(); - $('#total').html(json.total); taskList = new Array(); taskOrder = new Array(); taskCnt.past = taskCnt.today = taskCnt.soon = 0; @@ -48,6 +47,10 @@ function loadTasks() if(!item.compl) changeTaskCnt(item.dueClass); }); refreshTaskCnt(); + if(filter.due == '') $('#total').html(taskCnt.total); + else if(filter.due == 'past') $('#total').html(taskCnt.past); + else if(filter.due == 'today') $('#total').html(taskCnt.today); + else if(filter.due == 'soon') $('#total').html(taskCnt.soon); $('#tasklist').html(tasks); if(filter.compl) showhide($('#compl_hide'),$('#compl_show')); else showhide($('#compl_show'),$('#compl_hide')); @@ -462,11 +465,6 @@ function doAuth(form) if(json.logged) { flag.isLogged = true; - if(filter.search != '') { - filter.search = ''; - $('#searchbarkeyword').text(''); - $('#searchbar').hide(); - } updateAccessStatus(); loadLists(); } @@ -844,6 +842,11 @@ function mttTabSelected(el, indx) if(!tabLists[indx]) return; if(indx != curList.i) { $('#tasklist').html(''); + if(filter.search != '') { + filter.search = ''; + $('#searchbarkeyword').text(''); + $('#searchbar').hide(); + } } curList = tabLists[indx]; flag.tagsChanged = true; @@ -922,6 +925,11 @@ function toggleAllNotes(showhide) function loadLists(onInit) { if(flag.needAuth && !flag.isLogged && !flag.canAllRead) return false; + if(filter.search != '') { + filter.search = ''; + $('#searchbarkeyword').text(''); + $('#searchbar').hide(); + } setAjaxErrorTrigger(); nocache = '&rnd='+Math.random(); $.getJSON('ajax.php?loadLists'+nocache, function(json){ @@ -965,7 +973,7 @@ function renameCurList() { if(!curList) return; var r = prompt(lang.renameList, dehtml(curList.name)); - if(r == null) return; + if(r == null || r == '') return; setAjaxErrorTrigger() nocache = '&rnd='+Math.random(); $.post('ajax.php?'+nocache, { renameList:1, id:curList.id, name:r }, function(json){ @@ -979,6 +987,19 @@ function renameCurList() }, 'json'); } +function deleteCurList() +{ + var r = confirm(lang.deleteList); + if(!r) return; + setAjaxErrorTrigger() + $.post('ajax.php?'+'&rnd='+Math.random(), { deleteList:1, id:curList.id }, function(json){ + resetAjaxErrorTrigger(); + if(!parseInt(json.total)) return; + loadLists(); + }, 'json'); + +} + function addsearchToggle(toSearch) { if(toSearch) diff --git a/src/ajax.php b/src/ajax.php index c9dbeb9..895cbf4 100644 --- a/src/ajax.php +++ b/src/ajax.php @@ -345,6 +345,26 @@ elseif(isset($_POST['renameList'])) echo json_encode($t); exit; } +elseif(isset($_POST['deleteList'])) +{ + check_write_access(); + stop_gpc($_POST); + $t = array(); + $t['total'] = 0; + $id = (int)_post('id'); + $db->ex("BEGIN"); + $db->ex("DELETE FROM lists WHERE id=$id"); + $t['total'] = $db->affected(); + if($t['total']) { + $db->ex("DELETE FROM tags WHERE list_id=$id"); + # sqlite doesnt support DELETE FROM INNNER JOIN + $db->ex("DELETE FROM tag2task WHERE task_id IN (SELECT id FROM todolist WHERE list_id=$id)"); + $db->ex("DELETE FROM todolist WHERE list_id=$id"); + } + $db->ex("COMMIT"); + echo json_encode($t); + exit; +} ################################################################################################### diff --git a/src/index.php b/src/index.php index c1c0f62..dcbeda9 100644 --- a/src/index.php +++ b/src/index.php @@ -194,7 +194,7 @@ $().ajaxStop( function(r,s) {$("#loading").fadeOut();} );
diff --git a/src/lang/class.default.php b/src/lang/class.default.php index a7c22f8..2c61b84 100644 --- a/src/lang/class.default.php +++ b/src/lang/class.default.php @@ -23,6 +23,7 @@ class DefaultLang 'addList' => "Create new list", 'addListDefault' => "Todo", 'renameList' => "Rename list", + 'deleteList' => "This will delete current list with all tasks in it.\\nAre you sure?", ); private $default_inc = array diff --git a/src/lang/en.php b/src/lang/en.php index d33054e..f2f933a 100644 --- a/src/lang/en.php +++ b/src/lang/en.php @@ -18,6 +18,7 @@ class Lang extends DefaultLang 'tagfilter' => "Tag:", 'addList' => "Create new list", 'renameList' => "Rename list", + 'deleteList' => "This will delete current list with all tasks in it.\\nAre you sure?", ); var $inc = array