-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
210 lines (202 loc) · 8.12 KB
/
index.php
File metadata and controls
210 lines (202 loc) · 8.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
session_start();
include 'api/functions.php';
$dbPath = $_SESSION['dbPath'];
?>
<!DOCTYPE html>
<html>
<head>
<title>
Kreegur - test logging system
</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<link href="css/jquery-ui.css" rel="stylesheet">
<style>
body {
font-family:arial;
}
.myButtons{
min-width:100px;
}
td {
padding:5px;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<td>
ID
</td>
<td>
Description
</td>
<td>
Start time
</td>
<td>
End time
</td>
<td>
Action
</td>
</tr>
</thead>
<tbody id="tbodyTasks">
</tbody>
</table>
<div id="dialogNewTask" title="New task" style="display:none;">
Description<br>
<input type="text" id="inputDescription">
<div id="divEnterDescription" style="color:red;display:none;">
Must enter a description
</div>
</div>
<div id="dialogDeleteTask" title="Delete task" style="display:none;">
Delete task?
<div id="divDeleteMessage" style="color:red;display:none;">
Error: no task selected
</div>
</div>
<button class="myButtons someOtherClass" id="buttonNewTask">New task</button>
<script src = "js/jquery-3.3.1.min.js"></script>
<script src = "js/jquery-ui.min.js"></script>
<script>
var taskId = -1; //current task id (-1 is not set)
$(document).ready(function(){
updateTasks();
$(".myButtons").button();
$("#dialogNewTask").dialog({
modal:true,
autoOpen:false,
buttons: {
Okay: function(){
var descr = $("#inputDescription").val();
if(descr.length == 0)
$("#divEnterDescription").show();
else{
//alert("will try to add new task with description of: "+descr);
$(this).dialog('close');
$.post(
'api/tasks.php',
{
action: 'newTask',
description: descr
},
function(data){
updateTasks();
if(data.error)
alert(data.message);
},
'json'
);
}
},
Cancel: function(){
$(this).dialog('close');
}
},
open: function(event, ui){
$("#inputDescription").val('');
$("#divEnterDescription").hide();
}
});
$("#dialogDeleteTask").dialog({
modal:true,
autoOpen:false,
buttons: {
Okay: function(){
if(taskId == -1)
$("#divDeleteMessage").show();
else{
//alert("will try to add new task with description of: "+descr);
$(this).dialog('close');
$.post(
'api/tasks.php',
{
action: 'deleteTask',
id: taskId
},
function(data){
updateTasks();
if(data.error)
alert(data.message);
taskId = -1;
},
'json'
);
}
},
Cancel: function(){
$(this).dialog('close');
}
},
open: function(event, ui){
$("#divDeleteMessage").hide();
}
});
$("#buttonNewTask").click(function(){
$("#dialogNewTask").dialog('open');
});
$('body').on('click','.finishTask',function(){
var id = $(this).attr('id').substr(6);
//alert("Should finish task with id of: "+id);
$.post(
'api/tasks.php',
{
action: 'endTask',
id: id
},
function(data){
updateTasks();
if(data.error)
alert(data.message);
},
'json'
);
});
$('body').on('click','.deleteTask',function(){
var id = $(this).attr('id').substr(6);
//alert("Should delete task with id of: "+id);
taskId = parseInt(id);
$("#dialogDeleteTask").dialog('open');
});
$('body').on('click','.configureTask',function(){
var id = $(this).attr('id').substr(9);
var url = 'taskConfigure.php?id='+id;
//alert("Should configure task with id of: "+id+' and url of: '+url);
window.open(url, '_self');
});
});
function updateTasks(){
$.post(
'api/tasks.php',
function(data){
//alert(JSON.stringify(data));
$("#tbodyTasks").empty();
$.each(data.tasks,function(index, value){
var html = '<tr><td>'+value.id+'</td>';
html += '<td>'+value.description+'</td>';
html += '<td>'+value.startTime.substr(0,19)+'</td>';
if(value.endTime == null)
html += '<td>On-going</td>';
else
html += '<td>'+value.endTime.substr(0,19)+'</td>';
html += '<td><button class="myButtons finishTask" id="finish'+value.id+'">Finish</button>';
html += '<button class="myButtons viewTask" id="view'+value.id+'">View data</button>';
html += '<button class="myButtons configureTask" id="configure'+value.id+'">Configure</button>';
html += '<button class="myButtons deleteTask" id="delete'+value.id+'">Delete</button></td>';
html += '</tr>';
$("#tbodyTasks").append(html);
$(".myButtons").button();
});
},
'json'
);
}
</script>
</body>
</html>