Commit 5e5d4c66 by sopham

can add task now

parent af8921ce
//var i = 0;
/*
//add new row to list after submitting
function addRow(){
if (document.getElementById('add-task').value!=''){
i++;
var title = document.getElementById('add-task').value;
var node = document.createElement('div');
node.innerHTML = '<input id="' + i + '" type="checkbox" class="hidden" name="checkbox"><label for="' + i + '" class="check--label"><span class="check--label-box"></span><span class="check--label-text">'+ title +'</span>';
var lastElement = parseInt(document.getElementById("doList").lastElementChild.getAttribute("id"));
if (!isNaN(lastElement)) {
node.setAttribute("id", lastElement + 1);
}
else {
node.setAttribute("id", 0);
}
$.ajax({
dataType: 'JSON',
url: 'get-id.php',
success: function(data){
})
//node.setAttribute("id", new_id);
document.getElementById('doList').appendChild(node);
}
}
*/
//delete all tasks
function deleteAll() {
var e = document.getElementById("doList");
......@@ -59,17 +31,13 @@ $("#imageUpload").change(function() {
readURL(this);
});
//display input from database
$(document).ready(function() {
//display input from the database
$.ajax({
dataType: 'JSON',
url: 'display.php',
success: function(data) {
//var items = [];
$.each( data, function(key, val) {
//i++;
//var title = val
var node = document.createElement('div');
node.innerHTML = '<input id="' + key + '" type="checkbox" class="hidden" name="checkbox"><label for="' + key + '" class="check--label"><span class="check--label-box"></span><span class="check--label-text">' + val + '</span>';
document.getElementById('doList').appendChild(node);
......@@ -77,35 +45,11 @@ $(document).ready(function() {
}
});
});
/*
//add id into the each task after load page
$.ajax({
dataType:'JSON',
url: 'add-id.php',
success: function(data) {
var i = 0;
var id = [];
$.each(data, function(key, val) {
id.push(val);
})
$('#doList').children('div').each(function () {
if($(this).attr('class') == "progress-container") { return; }
else {
$(this).attr('id', id[i]);
i++;
}
})
}
});
});
*/
//delete completed tasks
$(document).ready(function() {
$('#delete-complete').click(function() {
$("input.hidden:checkbox:checked").each(function() {
//$(this).parent().remove();
$("input.hidden:checkbox:checked").each(function() {
$.ajax({
type: "GET",
url: "delete-complete.php",
......
//add user input to database
$("#addAction").submit(function(event) {
event.preventDefault();
var task = $("#add-task").val();
var task = $("#add-task").val();
if (task == '') return;
$.ajax({
url: "insert.php",
type:"POST",
data:{
"task": task },
success: function(data) {
$("#add-task").val("");
var new_id = data;
if (document.getElementById('add-task').value='') {
var title = document.getElementById('add-task').value();
if (document.getElementById('add-task').value!='') {
var title = document.getElementById('add-task').value;
var node = document.createElement('div');
node.innerHTML = '<input id="' + new_id + '" type="checkbox" class="hidden" name="checkbox"><label for="' + new_id + '" class="check--label"><span class="check--label-box"></span><span class="check--label-text">' + title + '</span>';
node.setAttribute("id", new_id);
document.getElementById('doList').appendChild(node);
}
$("#add-task").val("");
}
});
});
......@@ -34,6 +34,12 @@ input.addEventListener("keyup", function(event) {
$("#delete-button").click(function() {
$.ajax({
url: "delete-all.php",
type: "POST"
type: "POST",
success: function(data) {
var e = document.getElementById("doList");
while(e.firstChild) {
e.removeChild(e.firstChild);
}
}
});
});
......@@ -53,7 +53,7 @@ if(!isset($_SESSION['loggedin'])) {
<form action="dbconnection.php" method="POST" id="addAction">
<input type="text" id="add-task" onkeypress="return event.keyCode != 13" name="add-task" placeholder="Add tasks..." autocomplete="off">
<!--<input type="submit" class="add-button" id="add" onclick="insert(); addRow(); onFormSubmit();" name="add-button" value="Add">-->
<input type="submit" class="add-button" id="add" onclick="addRow();" onkeypress="return searchKeyPress(event);" name="add-button" value="Add">
<input type="submit" class="add-button" id="add" onkeypress="return searchKeyPress(event);" name="add-button" value="Add">
</form>
<form class="task-board card" class="list" id="form">
<div class="list-item" id="doList">
......
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#imagePreview').css('background-image', 'url('+e.target.result +')');
$('#imagePreview').hide();
$('#imagePreview').fadeIn(650);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imageUpload").change(function() {
readURL(this);
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment