+ edit settings page

This commit is contained in:
Max Pozdeev 2009-10-05 12:19:09 +04:00
parent ffdab16e64
commit c966be4f6f
7 changed files with 103 additions and 30 deletions

View file

@ -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');
}

View file

@ -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, "<?php\n\$config = array();\n$s?>");
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, "<?php\n\$config = array();\n$s?>");
fclose($f);
}
?>

View file

@ -91,10 +91,10 @@ $().ajaxStop( function(r,s) {$("#loading").fadeOut();} );
<div id="loading"><img src="images/loading1.gif"></div>
<div id="bar">
<div style="float:left"><span id="msg" onClick="toggleMsgDetails()"></span><div id="msgdetails"></div></div>
<div id="msg" style="float:left"><span class="msg-text" onClick="toggleMsgDetails()"></span><div class="msg-details"></div></div>
<div align="right">
<span class="menu-owner">
<a href="settings.php">Settings</a>
<a href="#settings" onClick="showSettings();return false;"><?php __('a_settings');?></a>
</span>
<span class="bar-delim" style="display:none"> | </span>
<span id="bar_auth">
@ -200,6 +200,8 @@ $().ajaxStop( function(r,s) {$("#loading").fadeOut();} );
<div class="li mtt-need-list" onClick="deleteCurList()"><?php __('list_delete');?></div>
</div>
<div id="page_ajax" style="display:none"></div>
</div>
<div id="space"></div>
</div>

View file

@ -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();

View file

@ -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",
);
}

View file

@ -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 <form method=post><input type=hidden name=install value=1><input type=submit value=' Install '></form>");
}
@ -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");

View file

@ -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; }