cleanup of task widget - make jquery workflow a bit smoother
This commit is contained in:
parent
afbbc9cd72
commit
49c4aa1a54
@ -927,10 +927,10 @@ function tasks_fetch($arr) {
|
||||
|
||||
$ret = array();
|
||||
$sql_extra = " and event_status != 'COMPLETED' ";
|
||||
if(argc() > 1 && argv(1) === 'all')
|
||||
if($arr && $arr['all'] == 1)
|
||||
$sql_extra = '';
|
||||
|
||||
$r = q("select * from event where type = 'task' and uid = %d $sql_extra ",
|
||||
$r = q("select * from event where type = 'task' and uid = %d $sql_extra order by created desc",
|
||||
intval(local_channel())
|
||||
);
|
||||
|
||||
|
@ -1047,17 +1047,17 @@ function widget_tasklist($arr) {
|
||||
|
||||
|
||||
require_once('include/event.php');
|
||||
$o .= '<script>$("#tasklist-new-summary").keyup(function(e) { if (e.keyCode == 13) { $.post( "tasks/new", $("#tasklist-new").serialize() ); return false; } });</script>';
|
||||
$o .= '<script>function taskComplete(id) { $.post("tasks/complete/"+id); }</script>';
|
||||
$o .= '<div class="widget">' . '<h3>' . t('Tasks') . '</h3>';
|
||||
$x = tasks_fetch(array());
|
||||
|
||||
if($x['success']) {
|
||||
foreach($x['tasks'] as $y) {
|
||||
$o .= '<div class="tasklist-item"><input type="checkbox" onchange="taskComplete(' . $y['id'] . '); return false;" /> ' . $y['summary'] . '</div>';
|
||||
$o .= '<script>var tasksShowAll = 0; $(document).ready(function() { tasksFetch(); $("#tasklist-new-form").submit(function(event) { event.preventDefault(); $.post( "tasks/new", $("#tasklist-new-form").serialize(), function(data) { tasksFetch(); $("#tasklist-new-summary").val(""); } ); return false; } )});</script>';
|
||||
$o .= '<script>function taskComplete(id) { $.post("tasks/complete/"+id, function(data) { tasksFetch();}); }
|
||||
function tasksFetch() {
|
||||
$.get("tasks/fetch" + ((tasksShowAll) ? "/all" : ""), function(data) {
|
||||
$(".tasklist-tasks").html(data.html);
|
||||
});
|
||||
}
|
||||
}
|
||||
$o .= '<form id="tasklist-new" action="tasks/new" method="post"><input id="tasklist-new-summary" type="text" name="summary" value="" /></form>';
|
||||
</script>';
|
||||
|
||||
$o .= '<div class="widget">' . '<h3>' . t('Tasks') . '</h3><div class="tasklist-tasks">';
|
||||
$o .= '</div><form id="tasklist-new-form" action="" ><input id="tasklist-new-summary" type="text" name="summary" value="" /></form>';
|
||||
$o .= '</div>';
|
||||
return $o;
|
||||
|
||||
|
@ -1,8 +1,39 @@
|
||||
<?php
|
||||
|
||||
require_once('include/event.php');
|
||||
|
||||
|
||||
function tasks_init(&$a) {
|
||||
|
||||
|
||||
// logger('request: ' . print_r($_REQUEST,true));
|
||||
|
||||
$arr = array();
|
||||
|
||||
if(argc() > 1 && argv(1) === 'fetch') {
|
||||
if(argc() > 2 && argv(2) === 'all')
|
||||
$arr['all'] = 1;
|
||||
|
||||
$x = tasks_fetch($arr);
|
||||
if($x['tasks']) {
|
||||
$x['html'] = '';
|
||||
foreach($x['tasks'] as $y) {
|
||||
$x['html'] .= '<div class="tasklist-item"><input type="checkbox" onchange="taskComplete(' . $y['id'] . '); return false;" /> ' . $y['summary'] . '</div>';
|
||||
}
|
||||
}
|
||||
json_return_and_die($x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function tasks_post(&$a) {
|
||||
|
||||
|
||||
// logger('post: ' . print_r($_POST,true));
|
||||
|
||||
|
||||
if(! local_channel())
|
||||
return;
|
||||
|
||||
@ -71,27 +102,6 @@ function tasks_content(&$a) {
|
||||
if(! local_channel())
|
||||
return;
|
||||
|
||||
$ret = array();
|
||||
$sql_extra = " and event_status != 'COMPLETED' ";
|
||||
if(argc() > 1 && argv(1) === 'all')
|
||||
$sql_extra = '';
|
||||
dbg(1);
|
||||
$r = q("select * from event where type = 'task' and uid = %d $sql_extra ",
|
||||
intval(local_channel())
|
||||
);
|
||||
dbg(0);
|
||||
|
||||
$ret['success'] = (($r) ? true : false);
|
||||
if($r) {
|
||||
$ret['tasks'] = $r;
|
||||
}
|
||||
|
||||
// return $ret;
|
||||
|
||||
return json_encode($ret);
|
||||
|
||||
// json_return_and_die($ret);
|
||||
|
||||
|
||||
|
||||
return '';
|
||||
}
|
Reference in New Issue
Block a user