From 6d6f2482d8216ffc3a849919495d55d42895f28f Mon Sep 17 00:00:00 2001 From: Max Pozdeev Date: Thu, 22 Oct 2009 10:43:19 +0400 Subject: [PATCH] + complete form to create task --- src/ajax.js | 40 ++++++++++++++++++++++++++++++++++-- src/ajax.php | 42 ++++++++++++++++++++++++++++++++++++++ src/index.php | 4 +++- src/lang/class.default.php | 2 ++ src/lang/en.php | 2 ++ 5 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 0c74805..948b33e 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -286,10 +286,24 @@ function editTask(id) for(var i=0; i').appendTo('body').css('opacity', 0.5).show(); //clear selection if(document.selection && document.selection.empty) document.selection.empty(); else if(window.getSelection) window.getSelection().removeAllRanges(); + if(isAdd) { + showhide($('#page_taskedit>h3.mtt-inadd'), $('#page_taskedit>h3.mtt-inedit')); + $('#page_taskedit>form').attr('onSubmit', 'return submitFullTask(this)'); + } + else { + showhide( $('#page_taskedit>h3.mtt-inedit'), $('#page_taskedit>h3.mtt-inadd')); + $('#page_taskedit>form').attr('onSubmit', 'return saveTask(this)'); + } var w = $('#page_taskedit'); if(!flag.windowTaskEditMoved) { @@ -304,12 +318,11 @@ function editTask(id) } if(x < 0) x = 0; if(y < 0) y = 0; - w.css('left',x).css('top',y); + w.css({left:x, top:y}); tmp.editformpos = [x, y]; } w.fadeIn('fast'); //.show(); $(document).bind('keydown', cancelEdit); - return false; } function cancelEdit(e) @@ -1116,3 +1129,26 @@ function saveSettings(frm) } }, 'json'); } + +function submitFullTask(form) +{ + if(flag.needAuth && !flag.isLogged && flag.canAllRead) 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){ + resetAjaxErrorTrigger(); + if(!parseInt(json.total)) return; + $('#total').text( parseInt($('#total').text()) + parseInt(json.total) ); + form.task.value = ''; + var item = json.list[0]; + taskList[item.id] = item; + taskOrder.push(parseInt(item.id)); + $('#tasklist').append(prepareTaskStr(item)); + changeTaskOrder(item.id); + cancelEdit(); + $('#taskrow_'+item.id).effect("highlight", {color:theme.newTaskFlashColor}, 2000); + }, 'json'); + $("#edittags").flushCache(); + flag.tagsChanged = true; + return false; +} \ No newline at end of file diff --git a/src/ajax.php b/src/ajax.php index ff929a4..1a0c55f 100644 --- a/src/ajax.php +++ b/src/ajax.php @@ -105,6 +105,48 @@ elseif(isset($_GET['newTask'])) echo json_encode($t); exit; } +elseif(isset($_GET['fullNewTask'])) +{ + check_write_access(); + stop_gpc($_POST); + $listId = (int)_post('list'); + $title = trim(_post('title')); + $note = str_replace("\r\n", "\n", trim(_post('note'))); + $prio = (int)_post('prio'); + if($prio < -1) $prio = -1; + elseif($prio > 2) $prio = 2; + $duedate = parse_duedate(trim(_post('duedate'))); + $t = array(); + $t['total'] = 0; + if($title == '') { + echo json_encode($t); + exit; + } + $tags = trim(_post('tags')); + if(isset($config['autotag']) && $config['autotag']) $tags .= ','._post('tag'); + $tz = (int)_post('tz'); + if( (isset($config['autotz']) && $config['autotz']==0) || $tz<-720 || $tz>720 || $tz%30!=0 ) $d = strftime("%Y-%m-%d %H:%M:%S"); + else $d = gmdate("Y-m-d H:i:s", time()+$tz*60); + $ow = 1 + (int)$db->sq("SELECT MAX(ow) FROM todolist WHERE list_id=$listId AND compl=0"); + if(is_null($duedate)) $duedate = 'NULL'; else $duedate = $db->quote($duedate); + $db->ex("BEGIN"); + $db->dq("INSERT INTO todolist (list_id,title,d,ow,prio,note,duedate) VALUES($listId,?,?,$ow,$prio,?,$duedate)", array($title,$d,$note)); + $id = $db->last_insert_id(); + if($tags) + { + $tag_ids = prepare_tags($tags, $listId); + if($tag_ids) { + update_task_tags($id, $tag_ids); + $db->ex("UPDATE todolist SET tags=? WHERE id=$id", $tags); + } + } + $db->ex("COMMIT"); + $r = $db->sqa("SELECT * FROM todolist WHERE id=$id"); + $t['list'][] = prepareTaskRow($r); + $t['total'] = 1; + echo json_encode($t); + exit; +} elseif(isset($_GET['deleteTask'])) { check_write_access(); diff --git a/src/index.php b/src/index.php index 92b6d3b..95f6d09 100644 --- a/src/index.php +++ b/src/index.php @@ -115,6 +115,7 @@ $().ajaxStop( function(r,s) {$("#loading").fadeOut();} );
+   |
@@ -142,7 +143,8 @@ $().ajaxStop( function(r,s) {$("#loading").fadeOut();} );