tangled
alpha
login
or
join now
stau.space
/
aecc-db
0
fork
atom
AECC database project.
0
fork
atom
overview
issues
pulls
pipelines
feat: Activity CRUD UI finished.
Diego A. Estrada Rivera
9 months ago
ed9cecfe
9500c463
+159
-45
2 changed files
expand all
collapse all
unified
split
activity.html
lib
activity.js
+63
-44
activity.html
···
1
1
-
<div id="activityFunctionality" hidden>
2
2
-
activity are <b>AWESOME</b>
3
3
-
<br />
4
4
-
What would you like to do?
5
5
-
<br />
6
6
-
<br />
7
7
-
<nav>
8
8
-
<button onclick="next('activityCreator')">Create</button>
9
9
-
<button onclick="next('activityFinder');">Find</button>
10
10
-
<button onclick="next('activityEditor');">Edit</button>
11
11
-
<button onclick="next('activityDeleter');">Delete</button>
12
12
-
</nav>
13
13
-
<br />
14
14
-
a activity . . .
1
1
+
<div id="allActivities" hidden>
2
2
+
<h1>Here is the list of activities:</h1>
3
3
+
<label for="activityFinderFilter">Filter the results:</label>
4
4
+
<search>
5
5
+
<input type="search" name="activityFinderFilter" onkeyup="tableFilter(event, allActivitiesTable);" placeholder="filter...">
6
6
+
</search>
7
7
+
<table id="allActivitiesTable">
8
8
+
<thead>
9
9
+
<tr>
10
10
+
<th>ID</th>
11
11
+
<th style="width:80ch;">Title</th>
12
12
+
<th style="width:80ch;">Description</th>
13
13
+
<th>Date</th>
14
14
+
<th style="border:0px;"></th>
15
15
+
<th style="border:0px;"></th>
16
16
+
<tr>
17
17
+
</thead>
18
18
+
<tbody></tbody>
19
19
+
</table>
20
20
+
<button onclick="next('activityCreator');">Create a new activity</button>
15
21
</div>
16
22
17
23
<div id="activityCreator" hidden>
18
18
-
So you want to create a activity . . .
24
24
+
So you want to create an activity . . .
19
25
<br />
20
20
-
<form id="activityCreatorForm" onsubmit="ActivityCreatorFormHandler(event);">
26
26
+
<form id="activityCreatorForm" onsubmit="activityCreatorFormHandler(event);">
21
27
<fieldset>
22
28
<legend>activity</legend>
23
23
-
<input type="submit" value="Submit">
29
29
+
<br />
30
30
+
<label for="title">Title:</label>
31
31
+
<br />
32
32
+
<input name="title" type="text" minlength="1" maxlength="80" />
33
33
+
<br />
34
34
+
<br />
35
35
+
<label for="description">Description:</label>
36
36
+
<br />
37
37
+
<input name="description" type="text" minlength="1" maxlength="80" />
38
38
+
<br />
39
39
+
<br />
40
40
+
<label for="date">Date:</label>
41
41
+
<br />
42
42
+
<input name="date" type="datetime-local" max="2700" min="1700" />
43
43
+
<br />
44
44
+
<br />
45
45
+
<input type="submit" value="Submit" />
46
46
+
<br />
24
47
</fieldset>
25
48
</form>
26
49
</div>
27
50
28
28
-
<div id="activityFinder" hidden>
29
29
-
<h1>Here is the list of activity:</h1>
30
30
-
<label for="tableFilter">Filter the results:</label>
31
31
-
<search>
32
32
-
<input type="search" id="tableFilter" onkeyup="table_filter()" placeholder="filter...">
33
33
-
</search>
34
34
-
<table id="activityResultsTable"></table>
35
35
-
</div>
36
36
-
37
51
<div id="activityEditor" hidden>
38
38
-
Time to edit a activity. First, choose a Activity:
39
39
-
<br />
40
40
-
<br />
41
41
-
<select id="activityEditorOptions" onchange="loadActivityEditorSubmission();" ></select>
42
42
-
<div id="activityEditorMenu" hidden>
43
43
-
Current activity description:
44
44
-
<br />
45
45
-
Field1: <span id="activityEditorField1"></span>
46
46
-
Field2: <span id="activityEditorField2"></span>
47
47
-
<br />
48
48
-
<form id="activityEditorForm" onsubmit="ActivityEditorFormHandler(event);">
49
49
-
<fieldset>
50
50
-
<legend>Edit activity:</legend>
51
51
-
<input type="submit" value="Submit" />
52
52
-
<input type="hidden" id="activityEditorSubmissionId" value="" />
53
53
-
</fieldset>
54
54
-
</form>
55
55
-
</div>
52
52
+
<form id="activityEditorForm" onsubmit="activityEditorFormHandler(event);">
53
53
+
<fieldset>
54
54
+
<legend>Edit:</legend>
55
55
+
<br />
56
56
+
<label for="title">Title:</label>
57
57
+
<br />
58
58
+
<input id="activityEditorTitle" type="text" name="title" minlength="1" maxlength="80" />
59
59
+
<br />
60
60
+
<br />
61
61
+
<label for="description">Description:</label>
62
62
+
<br />
63
63
+
<input id="activityEditorDescription" type="text" name="description" minlength="1" maxlength="80" />
64
64
+
<br />
65
65
+
<br />
66
66
+
<label for="date">Date:</label>
67
67
+
<br />
68
68
+
<input id="activityEditorDate" type="datetime-local" name="date" min="1700" max="2700" />
69
69
+
<br />
70
70
+
<br />
71
71
+
<input type="submit" value="Submit" />
72
72
+
<input type="hidden" id="activityEditorID" value="" />
73
73
+
</fieldset>
74
74
+
</form>
56
75
</div>
57
76
58
77
<div id="activityDeleter" hidden>
+96
-1
lib/activity.js
···
1
1
-
function activity() {}
1
1
+
function activityCreatorFormHandler(event) {
2
2
+
event.preventDefault();
3
3
+
try {
4
4
+
const payload = JSON.stringify({
5
5
+
t: "activity",
6
6
+
title: event.target[1].value,
7
7
+
description: event.target[2].value,
8
8
+
date: event.target[3].value
9
9
+
});
10
10
+
if (confirm("Are you sure you want to create a new activity?")) {
11
11
+
fetch(URL + "/api/v1/create/", {
12
12
+
method: "POST",
13
13
+
headers: {
14
14
+
"Content-Type": "application/json"
15
15
+
},
16
16
+
body: payload
17
17
+
}).then(resp => {
18
18
+
if (resp.status != 201) {
19
19
+
const msg = `Error creating activity, status: ${resp.status}`;
20
20
+
alert(msg);
21
21
+
throw msg;
22
22
+
}
23
23
+
return resp.json();
24
24
+
}).then(json => {
25
25
+
alert(`Succesfully created activity with ID: ${json.a_id}`);
26
26
+
restart();
27
27
+
});
28
28
+
}
29
29
+
} catch (error) {
30
30
+
console.error(error.message);
31
31
+
}
32
32
+
}
33
33
+
34
34
+
function editActivity(obj) {
35
35
+
activityEditorID.value = obj[0];
36
36
+
activityEditorTitle.value = obj[1];
37
37
+
activityEditorDescription.value = obj[2];
38
38
+
activityEditorDate.value = obj[3];
39
39
+
next('activityEditor');
40
40
+
}
41
41
+
42
42
+
function activityEditorFormHandler(event) {
43
43
+
event.preventDefault();
44
44
+
try {
45
45
+
if (confirm("Do you want to edit this product?")) {
46
46
+
payload = JSON.stringify({
47
47
+
t: "activity",
48
48
+
a_id: event.target[5].value,
49
49
+
title: event.target[1].value,
50
50
+
description: event.target[2].value,
51
51
+
date: event.target[3].value
52
52
+
})
53
53
+
fetch(URL + "/api/v1/update/", {
54
54
+
method: "POST",
55
55
+
headers: {
56
56
+
"Content-Type": "application/json",
57
57
+
},
58
58
+
body: payload
59
59
+
}).then(resp => {
60
60
+
if (resp.status != 201) {
61
61
+
const msg = `Error updating activity, status: ${resp.status}`;
62
62
+
alert(msg);
63
63
+
throw msg;
64
64
+
}
65
65
+
return resp.json();
66
66
+
}).then(json => {
67
67
+
alert(`Succesfully updated activity with ID: ${json.a_id}`);
68
68
+
restart();
69
69
+
});
70
70
+
}
71
71
+
} catch (e) {
72
72
+
console.error(e.message);
73
73
+
}
74
74
+
}
75
75
+
76
76
+
function deleteActivity(obj) {
77
77
+
const a_id = obj[0];
78
78
+
if (confirm("Are you sure?")) {
79
79
+
fetch(URL + "/api/v1/delete/", {
80
80
+
method: "POST",
81
81
+
headers: {
82
82
+
"Content-Type": "application/json"
83
83
+
},
84
84
+
body: JSON.stringify({t: "activity", a_id: a_id})
85
85
+
}).then(resp => {
86
86
+
if (resp.status != 204) {
87
87
+
const msg = `Error deleting activity, status: ${resp.status}`;
88
88
+
alert(msg);
89
89
+
throw msg;
90
90
+
} else {
91
91
+
alert(`Succesfully deleted activity with ID: ${a_id}`);
92
92
+
restart();
93
93
+
}
94
94
+
});
95
95
+
}
96
96
+
}