diff --git a/src/ajax.js b/src/ajax.js index bd3d5f0..2aab04a 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,7 +1,7 @@ theme = { newTaskFlashColor: '#ffffaa', editTaskFlashColor: '#bbffaa', - errorFlashColor: '#ffffff' + msgFlashColor: '#ffffff' }; //Global vars @@ -25,6 +25,7 @@ var oBtnMenu = {}; var tabLists = []; var curList = 0; var tagsList = []; +var page = {cur:'', prev:''}; function loadTasks() { @@ -143,7 +144,7 @@ function setAjaxErrorTrigger() $("#msg").ajaxError(function(event, request, settings){ var errtxt; if(request.status == 0) errtxt = 'Bad connection'; - else if(request.status != 200) errtxt = 'HTTP (ajax.php): '+request.status+'/'+request.statusText; + else if(request.status != 200) errtxt = 'HTTP: '+request.status+'/'+request.statusText; else errtxt = request.responseText; flashError(lang.error, errtxt); }); @@ -151,15 +152,23 @@ function setAjaxErrorTrigger() function flashError(str, details) { - $("#msg").text(str).css('display','block'); - $("#msgdetails").text(details); + $("#msg>.msg-text").text(str) + $("#msg>.msg-details").text(details); $("#loading").hide(); - $("#msg").effect("highlight", {color:theme.errorFlashColor}, 700); + $("#msg").addClass('mtt-error').effect("highlight", {color:theme.msgFlashColor}, 700); +} + +function flashInfo(str, details) +{ + $("#msg>.msg-text").text(str) + $("#msg>.msg-details").text(details); + $("#loading").hide(); + $("#msg").addClass('mtt-info').effect("highlight", {color:theme.msgFlashColor}, 700); } function toggleMsgDetails() { - var el = $("#msgdetails"); + var el = $("#msg>.msg-details"); if(!el) return; if(el.css('display') == 'none') el.show(); else el.hide() @@ -167,8 +176,7 @@ function toggleMsgDetails() function resetAjaxErrorTrigger() { - $("#msg").hide().unbind('ajaxError'); - $("#msgdetails").text('').hide(); + $("#msg").hide().removeClass('mtt-error mtt-info').unbind('ajaxError'); } function deleteTask(id) @@ -458,6 +466,8 @@ function updateAccessStatus() if(sortBy == 0) $("#tasklist").sortable('enable'); $("#authstr").text('').hide(); } + $('#page_ajax').hide(); + page.cur = ''; } function doAuth(form) @@ -1072,3 +1082,37 @@ function addEditTag(tag) var r = v.search(new RegExp('(^|,)\\s*'+tag+'\\s*(,|$)')); if(r < 0) $('#edittags').val(v+', '+tag); } + +function showSettings() +{ + if(page.cur == 'settings') return false; + $('#page_ajax').load('settings.php?ajax=yes',null,function(){ + showhide($('#page_ajax').addClass('mtt-page-settings'), $('#page_tasks')); + page.prev = page.cur; + page.cur = 'settings'; + }) +} + +function closeSettings() +{ + showhide($('#page_tasks'), $('#page_ajax').removeClass('mtt-page-settings')); + page.prev = page.cur; + page.cur = ''; + resetAjaxErrorTrigger(); +} + +function saveSettings(frm) +{ + if(!frm) return false; + var params = { save:'ajax' }; + $(frm).find("input:text,input:checked,select,:password").filter(":enabled").each(function() { params[this.name || '__'] = this.value; }); + $(frm).find(":submit").attr('disabled','disabled').blur(); + setAjaxErrorTrigger(); + $.post('settings.php?'+'&rnd='+Math.random(), params, function(json){ + resetAjaxErrorTrigger(); + if(json.saved) { + flashInfo(lang.settingsSaved); + setTimeout('window.location.reload();', 1000); + } + }, 'json'); +} diff --git a/src/common.php b/src/common.php index f9b843b..61aecc5 100644 --- a/src/common.php +++ b/src/common.php @@ -58,9 +58,9 @@ function _get($param,$defvalue = '') } } -function saveConfig($config) +class Config { - $params = array( + public static $params = array( 'db' => array('default'=>'sqlite', 'type'=>'s'), 'mysql.host' => array('default'=>'localhost', 'type'=>'s'), 'mysql.db' => array('default'=>'mytinytodo', 'type'=>'s'), @@ -74,24 +74,36 @@ function saveConfig($config) 'autotag' => array('default'=>1, 'type'=>'i'), 'duedateformat' => array('default'=>1, 'type'=>'i'), 'firstdayofweek' => array('default'=>1, 'type'=>'i'), - 'session' => array('default'=>'files', 'type'=>'s'), + 'session' => array('default'=>'files', 'type'=>'s', 'options'=>array('files','default')), ); - $s = ''; - foreach($params as $param=>$v) + public static function save($config) { - $val = isset($config[$param]) ? $config[$param] : $v['default']; - if($v['type']=='i') { - $s .= "\$config['$param'] = ".(int)$val.";\n"; - } - else { - $s .= "\$config['$param'] = '".str_replace(array("\\","'"),array("\\\\","\\'"),$val)."';\n"; + $s = ''; + foreach(self::$params as $param=>$v) + { + if(!isset($config[$param])) $val = $v['default']; + elseif(isset($v['options']) && !in_array($config[$param], $v['options'])) $val = $v['default']; + else $val = $config[$param]; + if($v['type']=='i') { + $s .= "\$config['$param'] = ".(int)$val.";\n"; + } + else { + $s .= "\$config['$param'] = '".str_replace(array("\\","'"),array("\\\\","\\'"),$val)."';\n"; + } } + $f = fopen('./db/config.php', 'w'); + if($f === false) throw new Exception("Error while saving config file"); + fwrite($f, ""); + fclose($f); + } + + public static function get($key, $config) + { + if(isset($config[$key])) return $config[$key]; + elseif(isset(self::$params[$key])) return self::$params[$key]['default']; + else return null; } - $f = fopen('./db/config.php', 'w'); - if($f === false) throw new Exception("Error while saving config file"); - fwrite($f, ""); - fclose($f); } ?> \ No newline at end of file diff --git a/src/index.php b/src/index.php index 2b782e9..13b54d7 100644 --- a/src/index.php +++ b/src/index.php @@ -91,10 +91,10 @@ $().ajaxStop( function(r,s) {$("#loading").fadeOut();} );
