summaryrefslogtreecommitdiffstats
path: root/static/functions/questions.js
blob: a55a0527f82417e33e033f148636077202991486 (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
$(document).ready(function() {
	$(".answer_link").click(function(e) {
		e.preventDefault();
		var id = this.id;
		$("#answer" + id).gtoggle();
	});

	$(".submit_button").click(function(e) {
		var id = this.id;
		$.ajax({
			type : "POST",
			url : "questions.php?action=take_answer_question",
			data : {
				"auth" : authkey,
				"id" : id,
				"answer" : $("#replybox_" + id).val()
			}
		}).done(function() {
			$("#question" + id).remove();
			$("#answer" + id).remove();
			$("#responses_for_" + id).remove();
		});
	});

	$(".view_responses").click(function(e) {
		e.preventDefault();
		var id = this.id;
		var respDiv = $("#responses_for_" + id);
		if (respDiv.length == 0) {
			respDiv = $('<div id="responses_for_' + id + '" style="display: none; margin-left: 20px;"></div>');
			$("#question" + id).after(respDiv);
			$.ajax({
				type : "GET",
				url : "questions.php?action=ajax_get_answers",
				dataType : "html",
				data : {
					"id" : id,
					"userid" : $(this).data("gazelle-userid")
				}
			}).done(function(response) {
				respDiv.html(response).show();
			});
		} else {
			respDiv.toggle();
		}
	});

	$(".ignore_link").click(function(e) {
		e.preventDefault();
		var id = this.id;
		$.ajax({
			type : "POST",
			url : "questions.php?action=take_ignore_question",
			data : {
				"auth" : authkey,
				"id" : id
			}
		}).done(function() {
			$("#question" + id).remove();
			$("#answer" + id).remove();
			$("#responses_for_" + id).remove();
		});
	});
});