summaryrefslogtreecommitdiffstats
path: root/static/functions/reports.js
blob: be0694f6cf7a20b31ea22d3de4a445ec6afdca8c (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
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
function toggleNotes(id) {
	var style = $('#notes_div_' + id).raw().style.display;
	if (style == "none") {
		$('#notes_div_' + id).raw().style.display = "block";
	}
	else {
		$('#notes_div_' + id).raw().style.display = "none";
	}
}

function saveNotes(id) {
	var notes = $('#notes_' + id).raw().value;
	notes = notes.replace(/(\r\n|\n\r|\r|\n)/g, '<br />');
	var post = new Array();
	post['id'] = id;
	post['notes'] = notes;
	ajax.post('reports.php?action=add_notes', post, function (response) {
		if (JSON.parse(response)['status'] != 'success') {
			alert("Error, could not save notes");
		}
	});

}

function claim(id) {
	var post = new Array();
	post['id'] = id;
	ajax.post('reports.php?action=claim', post, function (response) {
		var json = JSON.parse(response);
		if (json['status'] == 'failure') {
			alert("Error, could not claim.");
		}
		if (json['status'] == 'dupe') {
			alert("Oops, this report has already been claimed.");
		}
		if (json['status'] == 'success') {
			var username = json['username'];
			$('#claim_' + id).raw().innerHTML = '<a href="#" onclick="return false;">Claimed by ' + username + '</a>';
		}
	});
}

function unClaim(id) {
	var post = new Array();
	post['id'] = id;
	post['remove'] = '1';
	ajax.post('reports.php?action=unclaim', post, function (response) {
		var json = JSON.parse(response);
		if (json['status'] == 'success') {
			$('#claimed_' + id).raw().innerHTML = '<a href="#" id="claim_' + id + '" onclick="claim(' + id + '); return false;" class="brackets">Claim</a>';
		}
	});
}

function resolve(id, claimer) {
	var answer = true;
	if (!claimer) {
		if ($('#claimed_' + id).raw()) {
			var answer = confirm("This is a claimed report. Are you sure you want to resolve it?");
			if (answer)
				answer = true;
			else
				answer = false;
		}
	}
	if (answer) {
		ajax.post('reports.php?action=resolve', 'report_form_' + id, function (response) {
				var json = JSON.parse(response);
				if (json['status'] == 'success') {
					$('#report_' + id).remove();
				} else {
					alert(json['status']);
				}
			}
		);
	}
	return false;
}