From c966be4f6feab59635d5ca276e7438cc15d9c4bb Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Mon, 5 Oct 2009 12:19:09 +0400 Subject: [PATCH] + edit settings page --- src/ajax.js | 60 +++++++++++++++++++++++++++++++++----- src/common.php | 42 ++++++++++++++++---------- src/index.php | 6 ++-- src/lang/class.default.php | 2 ++ src/lang/en.php | 2 ++ src/setup.php | 6 ++-- src/style.css | 15 ++++++++-- 7 files changed, 103 insertions(+), 30 deletions(-) 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();} );
-
+
- Settings + @@ -200,6 +200,8 @@ $().ajaxStop( function(r,s) {$("#loading").fadeOut();} );
+ +
diff --git a/src/lang/class.default.php b/src/lang/class.default.php index abf9423..81a9df7 100644 --- a/src/lang/class.default.php +++ b/src/lang/class.default.php @@ -24,6 +24,7 @@ class DefaultLang 'addListDefault' => "Todo", 'renameList' => "Rename list", 'deleteList' => "This will delete current list with all tasks in it.\\nAre you sure?", + 'settingsSaved' => "Settings saved. Reloading...", ); private $default_inc = array @@ -74,6 +75,7 @@ class DefaultLang 'alltags' => "All tags:", 'alltags_show' => "Show all", 'alltags_hide' => "Hide all", + 'a_settings' => "Settings", ); var $js = array(); diff --git a/src/lang/en.php b/src/lang/en.php index 5b19ff6..49d4fd7 100644 --- a/src/lang/en.php +++ b/src/lang/en.php @@ -19,6 +19,7 @@ class Lang extends DefaultLang 'addList' => "Create new list", 'renameList' => "Rename list", 'deleteList' => "This will delete current list with all tasks in it.\\nAre you sure?", + 'settingsSaved' => "Settings saved. Reloading...", ); var $inc = array @@ -69,6 +70,7 @@ class Lang extends DefaultLang 'alltags' => "All tags:", 'alltags_show' => "Show all", 'alltags_hide' => "Hide all", + 'a_settings' => "Settings", ); } diff --git a/src/setup.php b/src/setup.php index 1abd966..a93501e 100644 --- a/src/setup.php +++ b/src/setup.php @@ -20,7 +20,7 @@ if(!isset($config['db'])) $config['db'] = 'sqlite'; } if(isset($config['allow']) && $config['allow'] == 'read') $config['allowread'] = 1; - #saveConfig($config); + #Config::save($config); } require_once('./init.php'); @@ -66,7 +66,7 @@ if(!$ver) if(!testConnect($error)) { exitMessage("Database connection error: $error"); } - saveConfig($config); + Config::save($config); exitMessage("This will create myTinyTodo database
"); } @@ -333,7 +333,7 @@ function update_12_13($db, $dbtype) { # update config global $config; - saveConfig($config); + Config::save($config); # and then db $db->ex("BEGIN"); diff --git a/src/style.css b/src/style.css index 6a27672..9b34d06 100644 --- a/src/style.css +++ b/src/style.css @@ -39,11 +39,16 @@ a { color:#0000ff; } #task, #search { color:#444444; width:300px; } .small-bar{ font-size:8pt; color:#999999; font-weight:normal;} -#msg { background-color:#ff3333; padding:1px 4px; display:none; font-weight:bold; cursor:pointer; } -#msgdetails { padding:1px 4px; border:1px solid #ff3333; background-color:#fff; display:none; max-width:700px; } #searchbar { font-size:10pt; font-weight:normal; display:none; margin-top:5px; } #searchbarkeyword { font-weight:bold; } +#msg .msg-text { padding:1px 4px; font-weight:bold; cursor:pointer; } +#msg .msg-details { padding:1px 4px; background-color:#fff; display:none; max-width:700px; } +#msg.mtt-error .msg-text { background-color:#ff3333; } +#msg.mtt-error .msg-details { border:1px solid #ff3333; } +#msg.mtt-info .msg-text { background-color:#EFC300; } +#msg.mtt-info .msg-details { border:1px solid #EFC300;} + #sort { margin-left:5px; font-size:8pt; font-weight:normal; border-bottom:1px dashed #ccc; padding:2px; cursor:pointer; -moz-user-select:none; -webkit-user-select: none; } #sort:hover { border-bottom:1px solid #bbb; } #sortform { overflow: hidden; z-index:101; background-color:#f9f9f9; border:1px solid #cccccc; padding:3px; } @@ -179,3 +184,9 @@ div.task-note-area textarea { color:#999999; width:100%; display:block; height:6 .mtt-btnmenu-container .li { margin:1px 0px; padding:2px; cursor:pointer; } .mtt-btnmenu-container .li:hover { background-color:#316AC5; color:white; } .mtt-btnmenu-container .li.mtt-need-list.li-disabled {color:#ACA899; } + +.mtt-settings-table { width:100%; border-collapse:collapse; } +.mtt-settings-table th, .mtt-settings-table td { border-bottom:1px solid #dedede; padding:8px; vertical-align:top; } +.mtt-settings-table .form-buttons { border-bottom:none; text-align:center; } +.mtt-settings-table th { text-align:left; width:210px; padding-left:8px; } +.mtt-settings-table .descr { font-size:8pt; font-weight:normal; color:#222; }