summaryrefslogtreecommitdiff
path: root/js/tasks.js
blob: 10483b368fdaafb18b59e5f276b8323afdc8b8eb (plain)
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
function handle_search_results(res) {
	//alert(res[0].title)
	if (res) {
		var tc = $("#table_container");
		tc.removeClass("hidden_results_table");
		// TODO: check if results_table is in tc's classes and add it if it isn't (jQuery stuff)
	}
	for (index in res) {
		obj = res[index]
		var tb = $("#results_tbody");
		tb.empty();
		//alert(tb);
		var tr = document.createElement("tr");
		var id_td = document.createElement("td");
		var id_text = document.createTextNode(String(obj.taskid));
		id_td.appendChild(id_text);
		var title_td = document.createElement("td");
		var title_text = document.createTextNode(obj.title);
		title_td.appendChild(title_text);
		var state_td = document.createElement("td");
		var state_text = document.createTextNode(obj.state);
		state_td.appendChild(state_text);
		var admin_td = document.createElement("td");
		var admin_text = document.createTextNode(obj.member_public.display_name);
		admin_td.appendChild(admin_text);
		var credits_total = 0;
		for (tdc_index in obj.tdcs) {
			tdc = obj.tdcs[tdc_index];
			credits_total += Number(tdc.remaining_credits);
		}
		alert(credits_total);
		var credits_td = document.createElement("td");
		var credits_text = document.createTextNode(String(credits_total));
		credits_td.appendChild(credits_text);
		tr.appendChild(id_td);
		tr.appendChild(title_td);
		tr.appendChild(state_td);
		tr.appendChild(admin_td);
		tr.appendChild(credits_td);
		tb.append(tr);
	}
}

function get_all_tasks() {
	fetch("tasks_api.php?action=get_all_tasks_simple").then(res => res.json()).then(res => handle_search_results(res));
}