From ae33f625a37c2c4091762c5d6f53df976a306a6c Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Sun, 24 Jan 2010 20:56:53 +0300 Subject: [PATCH] + ability to change order of tabs (thanks to Alexander Teague) --- src/ajax.js | 16 ++++++++++++---- src/ajax.php | 26 ++++++++++++++++++++++++-- src/themes/default/index.php | 4 ++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 5eb569e..1a20a64 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -12,7 +12,7 @@ var searchTimer; var objPrio = {}; var selTask = 0; var sortBy = 0; -var flag = { needAuth:false, isLogged:false, tagsChanged:true, windowTaskEditMoved:false }; +var flag = { needAuth:false, isLogged:false, tagsChanged:true, windowTaskEditMoved:false, autoTag:true }; var taskCnt = { total:0, past: 0, today:0, soon:0 }; var tmp = {}; var oBtnMenu = {}; @@ -797,7 +797,7 @@ function editFormResize(startstop, event) function mttTabSelected(id, indx) { $('#lists .mtt-tabs-selected').removeClass('mtt-tabs-selected'); - $('#lists li.list-id-'+tabLists[indx].id).addClass('mtt-tabs-selected'); + $('#list_'+tabLists[indx].id).addClass('mtt-tabs-selected'); if(!tabLists[indx]) return; if(indx != curList.i) { $('#tasklist').html(''); @@ -896,7 +896,7 @@ function loadLists(onInit, updAccess) $.each(json.list, function(i,item){ item.i = i; tabLists[i] = item; - ti += '
  • '+item.name+'
  • '; + ti += '
  • '+item.name+'
  • '; }); if(!curList) { $('#toolbar').children().removeClass('invisible'); @@ -944,7 +944,7 @@ function addList() item.i = i; tabLists[i] = item; if(i > 0) { - $('#lists>ul>li.mtt-tabs-button').before('
  • '+item.name+'
  • ') ; + $('#lists>ul>li.mtt-tabs-button').before('
  • '+item.name+'
  • ') ; mytinytodo.doAction('listAdded', {i:i, list:item}); } else loadLists(); @@ -1339,3 +1339,11 @@ function showCompletedToggle() else $('#btnShowCompleted').removeClass('mtt-item-checked'); loadTasks({setCompl:1}); } + +function listOrderChanged(event, ui) +{ + var order = $(this).sortable("serialize"); + $.post('ajax.php?changeListOrder'+'&rnd='+Math.random(), order, function(json){ + resetAjaxErrorTrigger(); + }, 'json'); +} diff --git a/src/ajax.php b/src/ajax.php index 4e9f52d..d8df67d 100644 --- a/src/ajax.php +++ b/src/ajax.php @@ -20,7 +20,7 @@ if(isset($_GET['loadLists'])) else $sqlWhere = ''; $t = array(); $t['total'] = 0; - $q = $db->dq("SELECT * FROM {$db->prefix}lists $sqlWhere ORDER BY id ASC"); + $q = $db->dq("SELECT * FROM {$db->prefix}lists $sqlWhere ORDER BY ow ASC, id ASC"); while($r = $q->fetch_assoc($q)) { $t['total']++; @@ -423,7 +423,29 @@ elseif(isset($_GET['moveTask'])) echo json_encode(array('total'=>$r?1:0)); exit; } - +elseif(isset($_GET['changeListOrder'])) +{ + check_write_access(); + stop_gpc($_POST); + $order = (array)_post('list'); + $t = array(); + $t['total'] = 0; + if($order) + { + $a = array(); + $setCase = ''; + foreach($order as $ow=>$id) { + $id = (int)$id; + $a[] = $id; + $setCase .= "WHEN id=$id THEN $ow\n"; + } + $ids = implode($a, ','); + $db->dq("UPDATE {$db->prefix}lists SET ow = CASE\n $setCase END WHERE id IN ($ids)"); + $t['total'] = 1; + } + echo json_encode($t); + exit; +} ################################################################################################### diff --git a/src/themes/default/index.php b/src/themes/default/index.php index 79b541f..c446c9a 100644 --- a/src/themes/default/index.php +++ b/src/themes/default/index.php @@ -48,6 +48,7 @@ $().ready(function(){ echo "\tflag.needAuth = true;\n"; if(is_logged()) echo "\tflag.isLogged = true;\n"; } + if(Config::get('autotag')) echo "\tflag.autoTag = true;\n"; echo "\tloadLists(1, 1);\n"; ?> $("#duedate").datepicker({dateFormat: '', firstDay: , @@ -65,6 +66,9 @@ $().ready(function(){ mytinytodo.addAction('listRenamed', tplSingleTabRenamed); mytinytodo.addAction('listAdded', tplSingleTabAdded); + + $("#lists ul").sortable({delay:150, update:listOrderChanged, items:'> :not(.mtt-tabs-button)'}); + }); $().ajaxSend( function(r,s) {$("#loading").show();} );