/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/js/manageCourses.js

  • Committer: elof.bigestans at gmail
  • Date: 2013-05-24 09:37:27 UTC
  • mto: This revision was merged to the branch mainline in revision 94.
  • Revision ID: elof.bigestans@gmail.com-20130524093727-i8t7zm9u4g3got57
* Updated ManageCourses, including JS+Jquery, popups, controller.
* Updated ajax.php, mainly function popup(). Also added some helpers related to ManageCourses

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Functions */
2
2
$(document).ready(function(){
3
 
        $('body').click(function(e){
4
 
                $('#addCourse').fadeOut(300);
5
 
                $('#editCourse').fadeOut(300);
6
 
        });     
7
 
        
8
 
        $('#addCourse').click(function(e){
9
 
                e.stopPropagation();
10
 
        });     
11
 
        $('#editCourse').click(function(e){
12
 
                e.stopPropagation();
13
 
        });     
14
 
        
15
 
        
 
3
 
16
4
        $('#addCourseButton').click(function(e){
17
 
                var target = $('#addCourse');
18
 
                if(target.is(":hidden")){
19
 
                        target.fadeIn(300);
20
 
                        e.stopPropagation();
21
 
                }
22
 
                else{
23
 
                        target.fadeOut(300);
24
 
                }
25
 
                
 
5
                $("#popup").load("ajax/popup/addCourse", function() {
 
6
                        $("#addCourse").fadeIn(300);
 
7
                        $("#addCourse .cancelButton").click(cancelButtonHandler);
 
8
                });
26
9
        });
27
10
        
28
11
        $('.manageCourseButton').click(function(e){
29
 
                var target = $('#editCourse');
30
 
                if(target.is(":hidden")){
31
 
 
32
 
                        var courseID = $(this).parent().prevAll(".courseID").html();
33
 
                        var courseName = $(this).parent().prevAll(".courseName").html();
34
 
                        var courseData = $(this).parent().prevAll(".courseData").html();
35
 
 
36
 
                        showManageCourse(courseID, courseName, courseData);
37
 
                        e.stopPropagation();
38
 
                }
39
 
                else{
40
 
                        target.fadeOut(300);
41
 
                }
42
 
                
43
 
        });
44
 
 
45
 
        $(".cancelButton").click(function(e) {
46
 
                $(this).closest(".manageCoursePopup").fadeOut(300);
47
 
                e.preventDefault();
48
 
                e.stopPropagation();
49
 
        });
 
12
                var courseID = $(this).parent().prevAll(".courseID").html();
 
13
                var courseName = $(this).parent().prevAll(".courseName").html();
 
14
                var courseData = $(this).parent().prevAll(".courseData").html();
 
15
 
 
16
                $("#popup").load("ajax/popup/editCourseDetails", function() {
 
17
                        $("#editCourse #editCourseName").attr("value", courseName);
 
18
                        $("#editCourse span").html(courseID);
 
19
                        $("#editCourse #editCourseID").attr("value", courseID)
 
20
                        $("#editCourse #editCourseData").attr("value", courseData);
 
21
 
 
22
                        $("#editCourse").fadeIn(300);
 
23
                        $("#editCourse .cancelButton").click(cancelButtonHandler);
 
24
                });
 
25
        });
 
26
 
 
27
        $(".cancelButton").click(cancelButtonHandler);
50
28
 
51
29
        $("#manageCourses table tr:odd").addClass("odd");
52
30
        $("#manageCourses table tr:even").addClass("even");
53
31
 
 
32
        /* When you click published/unpublished, the course should be toggled to the opposite state */
 
33
        $(".publishButton").click(publishButtonHandler);
 
34
 
 
35
        $("body").click(function() {
 
36
                $(".manageCoursePopup").fadeOut(300, function() {
 
37
                        $(this).remove();
 
38
                });
 
39
        });
 
40
 
 
41
        $("#popup").click(function(e) {
 
42
                e.stopPropagation();
 
43
        });
54
44
});
55
45
 
56
 
function showManageCourse(courseID, courseName, courseData) {
57
 
        $("#editCourse").fadeIn(300);
58
 
        $("#editCourse #editCourseName").attr("value", courseName);
59
 
        $("#editCourse span").html(courseID);
60
 
        $("#editCourse #editCourseID").attr("value", courseID)
61
 
        $("#editCourse #editCourseData").attr("value", courseData);
 
46
function publishButtonHandler(evt) {
 
47
        evt.preventDefault();
 
48
        evt.stopPropagation();
 
49
 
 
50
        // $(this) = the <a> being clicked. Fetch the a's href value. 
 
51
        var href = $(this).attr("href");
 
52
        var a = $(this);
 
53
        $.get(href, function() {
 
54
                var currentURL = window.location.pathname;
 
55
                var courseID = a.parent().parent().attr("data-course");
 
56
                a.parent().load(currentURL + " [data-course="+courseID+"] .coursePublishButton a", function(){
 
57
                        $(this).find("a").click(publishButtonHandler);
 
58
                });
 
59
        });
 
60
}
 
61
 
 
62
function cancelButtonHandler(e) {
 
63
        $(this).closest(".manageCoursePopup").fadeOut(300, function(){
 
64
                $(this).remove();
 
65
        });
 
66
        e.preventDefault();
 
67
        e.stopPropagation();
62
68
}
63
69
 
64
70
window.onkeyup = function(event){