mirror of
https://github.com/maxpozdeev/mytinytodo.git
synced 2026-03-11 08:55:27 +00:00
+ Can publish lists separetely
This commit is contained in:
parent
62ee0ded12
commit
d7ccf95a65
11 changed files with 76 additions and 54 deletions
56
src/ajax.js
56
src/ajax.js
|
|
@ -12,7 +12,7 @@ var searchTimer;
|
|||
var objPrio = {};
|
||||
var selTask = 0;
|
||||
var sortBy = 0;
|
||||
var flag = { needAuth:false, isLogged:false, canAllRead:true, tagsChanged:true, windowTaskEditMoved:false };
|
||||
var flag = { needAuth:false, isLogged:false, tagsChanged:true, windowTaskEditMoved:false };
|
||||
var img = {
|
||||
'note': ['images/page_white_text_add_bw.png','images/page_white_text_add.png'],
|
||||
'edit': ['images/page_white_edit_bw.png','images/page_white_edit.png'],
|
||||
|
|
@ -64,7 +64,7 @@ function prepareTaskStr(item, noteExp)
|
|||
{
|
||||
var id = parseInt(item.id);
|
||||
var prio = parseInt(item.prio);
|
||||
var readOnly = (flag.needAuth && flag.canAllRead && !flag.isLogged) ? true : false;
|
||||
var readOnly = (flag.needAuth && !flag.isLogged) ? true : false;
|
||||
return '<li id="taskrow_'+id+'" class="'+(item.compl?'task-completed ':'')+item.dueClass+'" onDblClick="editTask('+id+')"><div class="task-actions">'+
|
||||
'<a href="#" onClick="return toggleTaskNote('+id+')"><img src="'+img.note[0]+'" onMouseOver="this.src=img.note[1]" onMouseOut="this.src=img.note[0]" title="'+lang.actionNote+'"></a>'+
|
||||
'<a href="#" onClick="return editTask('+id+')"><img src="'+img.edit[0]+'" onMouseOver="this.src=img.edit[1]" onMouseOut="this.src=img.edit[0]" title="'+lang.actionEdit+'"></a>'+
|
||||
|
|
@ -343,7 +343,7 @@ function cancelEdit(e)
|
|||
|
||||
function saveTask(form)
|
||||
{
|
||||
if(flag.needAuth && !flag.isLogged && flag.canAllRead) return false;
|
||||
if(flag.needAuth && !flag.isLogged) return false;
|
||||
var tz = -1 * (new Date()).getTimezoneOffset();
|
||||
setAjaxErrorTrigger();
|
||||
var nocache = '&rnd='+Math.random();
|
||||
|
|
@ -463,14 +463,8 @@ function updateAccessStatus()
|
|||
$('#bar .menu-owner').hide();
|
||||
$('#bar .bar-delim').hide();
|
||||
}
|
||||
if(!flag.canAllRead && !flag.isLogged) {
|
||||
$('#page_tasks').hide();
|
||||
$('#lists').hide();
|
||||
} else {
|
||||
$('#page_tasks').show();
|
||||
}
|
||||
}
|
||||
if(flag.needAuth && flag.canAllRead && !flag.isLogged) {
|
||||
if(flag.needAuth && !flag.isLogged) {
|
||||
$('#page_tasks').addClass('readonly')
|
||||
$("#authstr").text(lang.readonly).show();
|
||||
addsearchToggle(1);
|
||||
|
|
@ -511,13 +505,7 @@ function logout()
|
|||
}, 'json');
|
||||
flag.isLogged = false;
|
||||
updateAccessStatus();
|
||||
if(flag.canAllRead) {
|
||||
loadTasks();
|
||||
}
|
||||
else {
|
||||
$('#total').html('0');
|
||||
$('#tasklist').html('');
|
||||
}
|
||||
loadLists();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -613,7 +601,7 @@ function setSort(v, init)
|
|||
else if(v == 2) $('#sort>.btnstr').text($('#sortByDueDate').text());
|
||||
else return;
|
||||
|
||||
if(flag.needAuth && flag.canAllRead && !flag.isLogged) {
|
||||
if(flag.needAuth && !flag.isLogged) {
|
||||
$("#tasklist").sortable('disable');
|
||||
return;
|
||||
}
|
||||
|
|
@ -624,7 +612,6 @@ function setSort(v, init)
|
|||
if(!init)
|
||||
{
|
||||
curList.sort = sortBy;
|
||||
tabLists[curList.i].sort = sortBy;
|
||||
changeTaskOrder();
|
||||
setAjaxErrorTrigger()
|
||||
var nocache = '&rnd='+Math.random();
|
||||
|
|
@ -833,7 +820,10 @@ function mttTabSelected(el, indx)
|
|||
$('#searchbarkeyword').text('');
|
||||
$('#searchbar').hide();
|
||||
}
|
||||
if(flag.canAllRead) $('#rss_icon').find('a').attr('href', 'feed.php?list='+tabLists[indx].id);
|
||||
//if(tabLists[indx].published)
|
||||
$('#rss_icon').find('a').attr('href', 'feed.php?list='+tabLists[indx].id);
|
||||
if(tabLists[indx].published) $('#btnPublish').addClass('mtt-item-checked');
|
||||
else $('#btnPublish').removeClass('mtt-item-checked');
|
||||
}
|
||||
curList = tabLists[indx];
|
||||
flag.tagsChanged = true;
|
||||
|
|
@ -911,7 +901,6 @@ function toggleAllNotes(show)
|
|||
|
||||
function loadLists(onInit)
|
||||
{
|
||||
if(flag.needAuth && !flag.isLogged && !flag.canAllRead) return false;
|
||||
if(filter.search != '') {
|
||||
filter.search = '';
|
||||
$('#searchbarkeyword').text('');
|
||||
|
|
@ -937,7 +926,11 @@ function loadLists(onInit)
|
|||
}
|
||||
curList = tabLists[0];
|
||||
loadTasks();
|
||||
if(flag.canAllRead) $('#rss_icon').show().find('a').attr('href', 'feed.php?list='+curList.id);
|
||||
if(curList.published) $('#btnPublish').addClass('mtt-item-checked');
|
||||
else $('#btnPublish').removeClass('mtt-item-checked');
|
||||
//if(curList.published)
|
||||
$('#rss_icon').show().find('a').attr('href', 'feed.php?list='+curList.id);
|
||||
$('#page_tasks').show();
|
||||
}
|
||||
else {
|
||||
curList = 0;
|
||||
|
|
@ -945,6 +938,7 @@ function loadLists(onInit)
|
|||
$('#page_tasks h3').children().addClass('invisible');
|
||||
$('#mylistscontainer .mtt-need-list').addClass('mtt-disabled');
|
||||
$('#rss_icon').hide();
|
||||
if(flag.needAuth && !flag.isLogged) $('#page_tasks').hide();
|
||||
}
|
||||
ti += '<li class="mtt-tabs-button menu-owner"><a href="#" id="mylists" onClick="btnMenu(this);return false;"><img src="images/arrdown.gif"></a></li>';
|
||||
$('#lists>ul').html(ti);
|
||||
|
|
@ -1011,7 +1005,7 @@ function addsearchToggle(toSearch)
|
|||
}
|
||||
else
|
||||
{
|
||||
if(flag.needAuth && flag.canAllRead && !flag.isLogged) return false;
|
||||
if(flag.needAuth && !flag.isLogged) return false;
|
||||
showhide($('#htab_newtask'), $('#htab_search'));
|
||||
// reload tasks when we return to task tab (from search tab)
|
||||
if(filter.search != '') {
|
||||
|
|
@ -1095,7 +1089,7 @@ function saveSettings(frm)
|
|||
|
||||
function submitFullTask(form)
|
||||
{
|
||||
if(flag.needAuth && !flag.isLogged && flag.canAllRead) return false;
|
||||
if(flag.needAuth && !flag.isLogged) return false;
|
||||
setAjaxErrorTrigger();
|
||||
var nocache = '&rnd='+Math.random();
|
||||
$.post('ajax.php?fullNewTask'+nocache, { list:curList.id, tag:filter.tag, title: form.task.value, note:form.note.value, prio:form.prio.value, tags:form.tags.value, duedate:form.duedate.value }, function(json){
|
||||
|
|
@ -1115,3 +1109,17 @@ function submitFullTask(form)
|
|||
flag.tagsChanged = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function publishCurList()
|
||||
{
|
||||
if(!curList) return false;
|
||||
setAjaxErrorTrigger();
|
||||
var nocache = '&rnd='+Math.random();
|
||||
$.post('ajax.php?publishList'+nocache, { list:curList.id, publish:curList.published?0:1 }, function(json){
|
||||
resetAjaxErrorTrigger();
|
||||
if(!parseInt(json.total)) return;
|
||||
curList.published = curList.published?0:1;
|
||||
if(curList.published) $('#btnPublish').addClass('mtt-item-checked');
|
||||
else $('#btnPublish').removeClass('mtt-item-checked');
|
||||
}, 'json');
|
||||
}
|
||||
|
|
|
|||
37
src/ajax.php
37
src/ajax.php
|
|
@ -16,23 +16,29 @@ $lang = new Lang();
|
|||
|
||||
if(isset($_GET['loadLists']))
|
||||
{
|
||||
check_read_access();
|
||||
if($needAuth && !is_logged()) $sqlWhere = 'WHERE published=1';
|
||||
else $sqlWhere = '';
|
||||
$t = array();
|
||||
$t['total'] = 0;
|
||||
$q = $db->dq("SELECT * FROM lists ORDER BY id ASC");
|
||||
$q = $db->dq("SELECT * FROM lists $sqlWhere ORDER BY id ASC");
|
||||
while($r = $q->fetch_assoc($q))
|
||||
{
|
||||
$t['total']++;
|
||||
$t['list'][] = array('id'=>$r['id'], 'name'=>htmlarray($r['name']), 'sort'=>$r['sorting']);
|
||||
$t['list'][] = array(
|
||||
'id' => $r['id'],
|
||||
'name' => htmlarray($r['name']),
|
||||
'sort' => (int)$r['sorting'],
|
||||
'published' => $r['published'] ? 1 :0,
|
||||
);
|
||||
}
|
||||
echo json_encode($t);
|
||||
exit;
|
||||
}
|
||||
elseif(isset($_GET['loadTasks']))
|
||||
{
|
||||
check_read_access();
|
||||
stop_gpc($_GET);
|
||||
$listId = (int)_get('list');
|
||||
check_read_access($listId);
|
||||
$sqlWhere = ' AND list_id='. $listId;
|
||||
if(_get('compl') == 0) $sqlWhere .= ' AND compl=0';
|
||||
$inner = '';
|
||||
|
|
@ -295,8 +301,8 @@ elseif(isset($_POST['logout']))
|
|||
}
|
||||
elseif(isset($_GET['suggestTags']))
|
||||
{
|
||||
check_read_access();
|
||||
$listId = (int)_get('list');
|
||||
check_read_access($listId);
|
||||
$begin = trim(_get('q'));
|
||||
$limit = (int)_get('limit');
|
||||
if($limit<1) $limit = 8;
|
||||
|
|
@ -325,6 +331,7 @@ elseif(isset($_GET['setPrio']))
|
|||
elseif(isset($_GET['tagCloud']))
|
||||
{
|
||||
$listId = (int)_get('list');
|
||||
check_read_access($listId);
|
||||
$a = array();
|
||||
$q = $db->dq("SELECT name,tags_count FROM tags WHERE list_id=$listId AND tags_count>0 ORDER BY tags_count ASC");
|
||||
while($r = $q->fetch_row()) {
|
||||
|
|
@ -409,6 +416,15 @@ elseif(isset($_GET['setSort']))
|
|||
echo json_encode(array('total'=>1));
|
||||
exit;
|
||||
}
|
||||
elseif(isset($_GET['publishList']))
|
||||
{
|
||||
check_write_access();
|
||||
$listId = (int)_post('list');
|
||||
$publish = (int)_post('publish');
|
||||
$db->ex("UPDATE lists SET published=? WHERE id=$listId", array($publish ? 1 : 0));
|
||||
echo json_encode(array('total'=>1));
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
###################################################################################################
|
||||
|
|
@ -436,9 +452,16 @@ function prepareTaskRow($r, $tz)
|
|||
);
|
||||
}
|
||||
|
||||
function check_read_access()
|
||||
function check_read_access($listId = null)
|
||||
{
|
||||
if(canAllRead() || is_logged()) return;
|
||||
global $db;
|
||||
if(!isset($config['password']) || $config['password'] == '') return true;
|
||||
if(is_logged()) return true;
|
||||
if($listId)
|
||||
{
|
||||
$id = $db->sq("SELECT id FROM lists WHERE id=? AND published=1", array($listId));
|
||||
if($id) return;
|
||||
}
|
||||
echo json_encode( array('total'=>0, 'list'=>array(), 'denied'=>1) );
|
||||
exit;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ class Config
|
|||
'title' => array('default'=>'', 'type'=>'s'),
|
||||
'lang' => array('default'=>'en', 'type'=>'s'),
|
||||
'password' => array('default'=>'', 'type'=>'s'),
|
||||
'allowread' => array('default'=>0, 'type'=>'i'),
|
||||
'smartsyntax' => array('default'=>1, 'type'=>'i'),
|
||||
'autotz' => array('default'=>1, 'type'=>'i'),
|
||||
'autotag' => array('default'=>1, 'type'=>'i'),
|
||||
|
|
|
|||
|
|
@ -19,10 +19,6 @@ $config['lang'] = "en";
|
|||
# or leave empty that everyone could read/write todolist
|
||||
$config['password'] = "";
|
||||
|
||||
# Allow readonly access for the others when password above is set:
|
||||
# 0 - No access, 1 - Read only
|
||||
$config['allowread'] = 0;
|
||||
|
||||
# To disable smart syntax uncomment the line below
|
||||
#$config['smartsyntax'] = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,16 +12,16 @@ require_once('./lang/class.default.php');
|
|||
require_once('./lang/'.$config['lang'].'.php');
|
||||
$lang = new Lang();
|
||||
|
||||
if(!canAllRead()) {
|
||||
die("Access denied!<br> Disable password protection or Grant read access");
|
||||
}
|
||||
|
||||
$listId = (int)_get('list');
|
||||
|
||||
$listData = $db->sqa("SELECT * FROM lists WHERE id=$listId");
|
||||
if($needAuth && (!$listData || !$listData['published'])) {
|
||||
die("Access denied!<br> List is not published.");
|
||||
}
|
||||
if(!$listData) {
|
||||
die("No such list");
|
||||
}
|
||||
|
||||
$listData['_feed_title'] = sprintf($lang->get('feed_title'), $listData['name']);
|
||||
$listData['_feed_descr'] = sprintf($lang->get('feed_description'), $listData['name']);
|
||||
htmlarray_ref($listData);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ $().ready(function(){
|
|||
if($needAuth)
|
||||
{
|
||||
echo "\tflag.needAuth = true;\n";
|
||||
if(!canAllRead()) echo "\tflag.canAllRead = false;\n";
|
||||
if(is_logged()) echo "\tflag.isLogged = true;\n";
|
||||
echo "\tupdateAccessStatus();\n";
|
||||
}
|
||||
|
|
@ -202,11 +201,12 @@ $().ajaxStop( function(r,s) {$("#loading").fadeOut();} );
|
|||
<div id="tagcloudcontent"></div>
|
||||
</div>
|
||||
|
||||
<div id="mylistscontainer" class="mtt-btnmenu-container" style="display:none">
|
||||
<div id="mylistscontainer" class="mtt-btnmenu-container mtt-btnmenu-hasimages" style="display:none">
|
||||
<ul>
|
||||
<li onClick="addList()"><?php _e('list_new');?></li>
|
||||
<li class="mtt-need-list" onClick="renameCurList()"><?php _e('list_rename');?></li>
|
||||
<li class="mtt-need-list" onClick="deleteCurList()"><?php _e('list_delete');?></li>
|
||||
<li class="mtt-need-list" id="btnPublish" onClick="publishCurList()"><?php _e('list_publish');?></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -40,14 +40,14 @@ if($needAuth && !isset($dontStartSession))
|
|||
session_start();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
function canAllRead()
|
||||
{
|
||||
global $config;
|
||||
if(!isset($config['password']) || $config['password'] == '') return true;
|
||||
if(isset($config['allowread']) && $config['allowread']) return true;
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
function is_logged()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ class DefaultLang
|
|||
'list_new' => "New list",
|
||||
'list_rename' => "Rename",
|
||||
'list_delete' => "Delete",
|
||||
'list_publish' => "Publish list",
|
||||
'alltags' => "All tags:",
|
||||
'alltags_show' => "Show all",
|
||||
'alltags_hide' => "Hide all",
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ class Lang extends DefaultLang
|
|||
'list_new' => "New list",
|
||||
'list_rename' => "Rename",
|
||||
'list_delete' => "Delete",
|
||||
'list_publish' => "Publish list",
|
||||
'alltags' => "All tags:",
|
||||
'alltags_show' => "Show all",
|
||||
'alltags_hide' => "Hide all",
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ if(isset($_POST['save']))
|
|||
$config['lang'] = _post('lang');
|
||||
if(isset($_POST['password']) && $_POST['password'] != '') $config['password'] = $_POST['password'];
|
||||
elseif(!_post('allowpassword')) $config['password'] = '';
|
||||
if(isset($_POST['allowread'])) $config['allowread'] = (int)_post('allowread');
|
||||
$config['smartsyntax'] = (int)_post('smartsyntax');
|
||||
$config['autotz'] = (int)_post('autotz');
|
||||
$config['autotag'] = (int)_post('autotag');
|
||||
|
|
@ -94,8 +93,8 @@ function selectOptions($a, $value, $default=null)
|
|||
<tr>
|
||||
<th>Password protection:</th>
|
||||
<td>
|
||||
<label><input type="radio" name="allowpassword" value="1" <?php if(_c('password')!='') echo "checked"; ?> onClick='$(this.form).find("input[name=password],input[name=allowread]").attr("disabled",false)'>Enabled</label> <br>
|
||||
<label><input type="radio" name="allowpassword" value="0" <?php if(_c('password')=='') echo "checked"; ?> onClick='$(this.form).find("input[name=password],input[name=allowread]").attr("disabled","disabled")'>Disabled</label> <br>
|
||||
<label><input type="radio" name="allowpassword" value="1" <?php if(_c('password')!='') echo "checked"; ?> onClick='$(this.form).find("input[name=password]").attr("disabled",false)'>Enabled</label> <br>
|
||||
<label><input type="radio" name="allowpassword" value="0" <?php if(_c('password')=='') echo "checked"; ?> onClick='$(this.form).find("input[name=password]").attr("disabled","disabled")'>Disabled</label> <br>
|
||||
</td></tr>
|
||||
|
||||
<tr>
|
||||
|
|
@ -103,13 +102,6 @@ function selectOptions($a, $value, $default=null)
|
|||
<td> <input type="password" name="password" <?php if(_c('password')=='') echo "disabled"; ?>> </td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Allow read-only:<br><span class="descr">(grant access to unauthorized users to view your tasks )</span></th>
|
||||
<td>
|
||||
<label><input type="radio" name="allowread" value="1" <?php if(_c('allowread')) echo "checked"; if(_c('password')=='') echo " disabled"; ?>>Enabled</label> <br>
|
||||
<label><input type="radio" name="allowread" value="0" <?php if(!_c('allowread')) echo "checked"; if(_c('password')=='') echo " disabled"; ?>>Disabled</label>
|
||||
</td></tr>
|
||||
|
||||
<tr>
|
||||
<th>Smart syntax:<br><span class="descr">(/priority/ task /tags/)</span></th>
|
||||
<td>
|
||||
|
|
|
|||
|
|
@ -183,6 +183,8 @@ div.task-note-area textarea { color:#999999; width:100%; display:block; height:6
|
|||
.mtt-btnmenu-container li:hover { background-color:#316AC5; color:white; }
|
||||
.mtt-btnmenu-container li.mtt-need-list.mtt-disabled { color:#ACA899; }
|
||||
.mtt-btnmenu-delimiter { height:0px; border-top:1px solid #cccccc; margin:2px -1px 2px -1px }
|
||||
.mtt-btnmenu-container.mtt-btnmenu-hasimages li { padding-left:18px; }
|
||||
.mtt-btnmenu-container li.mtt-item-checked { background-image:url(images/checkmark.gif); background-position:left center; background-repeat:no-repeat; }
|
||||
|
||||
.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; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue