/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
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
/* Functions */
$(document).ready(function(){

	$('#addCourseButton').click(function(e){
		$("#popup").load("ajax/popup/addCourse", function() {
			$("#addCourse").fadeIn(300);
			$("#addCourse .cancelButton").click(cancelButtonHandler);
		});
	});
	
	$('.manageCourseButton').click(function(e){
		var courseID = $(this).parent().prevAll(".courseID").html();
		var courseName = $(this).parent().prevAll(".courseName").html();
		var courseData = $(this).parent().prevAll(".courseData").html();

		$("#popup").load("ajax/popup/editCourseDetails", function() {
			$("#editCourse #editCourseName").attr("value", courseName);
			$("#editCourse span").html(courseID);
			$("#editCourse #editCourseID").attr("value", courseID)
			$("#editCourse #editCourseData").attr("value", courseData);

			$("#editCourse").fadeIn(300);
			$("#editCourse .cancelButton").click(cancelButtonHandler);
		});
	});

	$(".cancelButton").click(cancelButtonHandler);

	$("#manageCourses table tr:odd").addClass("odd");
	$("#manageCourses table tr:even").addClass("even");

	/* When you click published/unpublished, the course should be toggled to the opposite state */
	$(".publishButton").click(publishButtonHandler);

	$("html").click(function() {
		$(".manageCoursePopup").fadeOut(300, function() {
			$(this).remove();
		});
	});

	$("#popup").click(function(e) {
		e.stopPropagation();
	});
});

function publishButtonHandler(evt) {
	evt.preventDefault();
	evt.stopPropagation();

	// $(this) = the <a> being clicked. Fetch the a's href value. 
	var href = $(this).attr("href");
	var a = $(this);
	$.get(href, function() {
		var currentURL = window.location.pathname;
		var courseID = a.parent().parent().attr("data-course");
		a.parent().load(currentURL + " [data-course="+courseID+"] .coursePublishButton a", function(){
			$(this).find("a").click(publishButtonHandler);
		});
	});
}

function cancelButtonHandler(e) {
	$(this).closest(".manageCoursePopup").fadeOut(300, function(){
		$(this).remove();
	});
	e.preventDefault();
	e.stopPropagation();
}

window.onkeyup = function(event){
	if(event.keyCode==27){
		$('#addCourse').fadeOut(300);
	}
}