/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/bannermenu.js

  • Committer: Gustav Hatvigsson
  • Date: 2013-05-30 13:23:44 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20130530132344-s9h3dorus21m1628
Fixed a few things with the licensing infornation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* TODO: cHANGE THIS FILE ENTIRELY!!! CHANGE CALLED ID'S AND CLASSES */
2
2
 
3
 
/* TODO: Do I need these? */
4
 
/* Global variables */
5
 
var popoutMenu=0;
6
 
var expandedCourses=0;
7
 
 
8
3
/* Functions that run when the page loads */
9
4
$(document).ready(function() {
10
 
        /* Secures that the dropdownmenus are not shown on pageload */
11
 
        $('#dropdownCodeviewerMenu').hide();
12
 
        $('#dropdownUserMenu').show();
13
 
 
14
 
        /* Check courses in expanded menu */
15
 
        $('li.dropdownMenuCourseBlockNonActiveCourse').click(function(){
16
 
                $('li.dropdownMenuCourseBlockActiveCourse').addClass('dropdownMenuCourseBlockNonActiveCourse');
17
 
                $('li.dropdownMenuCourseBlockActiveCourse').removeClass('dropdownMenuCourseBlockActiveCourse');
18
 
 
19
 
                $(this).removeClass('dropdownMenuCourseBlockNonActiveCourse');
20
 
                $(this).addClass("dropdownMenuCourseBlockActiveCourse");
21
 
                /*TA BORT DEN ENA KLASSEN OCH ANVÄND TOGGLE*/
22
 
        });
23
 
 
24
 
        /* TODO: SHOULD OPEN A POPUP VIA AJAX */
25
 
        /* Blurs body and opens password changer */
26
 
        $('li[name="changePwd"]').click(function(e){
27
 
                e.stopPropagation();
28
 
                $('#popoutMenu').stop(false, false).slideUp(300);
29
 
                popoutMenu=0;
30
 
            $('body *').not('#passwordChanger, #passwordChanger *').animate({
31
 
                opacity:0.4}, 400);
32
 
                $('#passwordChanger').fadeIn(300);
33
 
                $('#passwordChanger').css('z-index', 3000);
34
 
        });
35
 
        
36
 
        $('body').click(function(e){
37
 
                $('#formContainer').fadeOut(300);
38
 
                $('#passwordChanger').fadeOut(300);
39
 
                $('body *').animate({
40
 
                opacity:1}, 400);
41
 
                $('#changePassword')[0].reset();
42
 
        });
43
 
        
44
 
        $('#passwordChanger').click(function(e){
45
 
                e.stopPropagation();
46
 
        });
47
 
        
48
 
        $('#formContainer').click(function(e){
49
 
                e.stopPropagation();
50
 
        });
51
 
        
52
 
        $('#popoutLink').click(function(e){
53
 
                if(popoutMenu==0){
54
 
                        $('#popoutMenu').stop(false, true).slideDown(300);
55
 
                        popoutMenu=1;
56
 
                        e.stopPropagation();
57
 
                // FIXA SÅ MENYN INTE KOMMER UPP IGEN
58
 
                }
59
 
                else if(popoutMenu==1){
60
 
                        $('#popoutMenu').stop(false, false).slideUp(300);       
61
 
                        popoutMenu=0;
62
 
                        e.stopPropagation();
63
 
                }
64
 
        });
65
 
        
66
 
        /* TODO: ??? */
67
 
        $('#loginLink').click(function(e){
68
 
                var target = $('#formContainer');
69
 
                if(target.is(":hidden")){
70
 
                        target.fadeIn(300);
71
 
                        $('#username').focus();
72
 
                        e.stopPropagation();
73
 
                }
74
 
                else{
75
 
                        target.fadeOut(300);
76
 
                }
 
5
 
 
6
        /* Makes the bannermenu scrollable horizontally but not vertically */
 
7
        $('#bannerBody').scrollToFixed();
 
8
 
 
9
        $("#dropdownUserMenu").click(function(e) {
 
10
                e.stopPropagation();
 
11
        });
 
12
 
 
13
        /* Sets the click-function for the usermenubutton */
 
14
        $('#bannerUserMenuButton').click(function(e){
 
15
                e.stopPropagation();
 
16
                $.get('ajax/isLoggedIn', function(response) {
 
17
                        if(response == 'yes') {
 
18
                                // If the user is logged in and the usermenu-div is hidden it's shown.
 
19
                                        // TODO: Secure that the courseblock-div is hidden when the usermenu-div is oppened.
 
20
                                        /*
 
21
                                        if($('#dropdownMenuCourseBlock').is(':visible')) {
 
22
                                                $('#dropdownMenuCourseBlock').hide();
 
23
                                        }
 
24
                                        $('#dropdownUserMenu').load('bannermenu.php #dropdownUserMenu');
 
25
                                        */
 
26
                                        //$("#dropdownMenuCourseBlock").hide();
 
27
                                // If the user is logged in and the usermenu-div is shown it's hidden.
 
28
                                $('#dropdownMenuCourseBlock').hide();
 
29
                                $('#dropdownUserMenu').toggle();
 
30
                        }
 
31
 
 
32
                        else {
 
33
                                // If the user is not logged in and the popup-div is hidden it's filled and shown.
 
34
                                if($('#popup').is(':hidden')) {
 
35
                                        $('#popup').load('ajax/popup/login', function(){
 
36
                                                $('#popup').show().click(function(e){e.stopPropagation();});
 
37
                                                $("#popup .hint").click(loginHint);
 
38
                                                $("#popup #username").focus().keydown(function() {
 
39
                                                        $("#popup .hint").addClass("available");
 
40
                                                });
 
41
                                                $("#popup form").submit(loginSubmit);
 
42
                                        });
 
43
                                }
 
44
                                // If the user is not logged in and the popup-div shows it's hidden.
 
45
                                else {
 
46
                                        $('#popup').hide();
 
47
                                }
 
48
                        }
 
49
                });
77
50
                
78
51
        });
 
52
        
 
53
        // TODO: Refresh the div with it's php before show.
 
54
        /* Expand and collapse courses in dropdown menu */
 
55
        $('#dropdownMenuExpandCourses').click(function(){
 
56
        
 
57
                // If the course block is collapsed it's expanded.
 
58
                if($('#dropdownMenuCourseBlock').is(':hidden')) {
 
59
                        $('#dropdownMenuCourseBlock').show();
 
60
                }
 
61
                // If the course block is expanded it's collapsed .
 
62
                else {
 
63
                        $('#dropdownMenuCourseBlock').hide();
 
64
                }
 
65
 
 
66
        });
 
67
 
 
68
        $("#dropdownMenuLogout").click(function(e) {
 
69
                e.stopPropagation();
 
70
                window.location.href = "./start/logout";
 
71
        });
 
72
 
 
73
        $("html").click(function(e) {
 
74
                e.stopPropagation();
 
75
                $("#dropdownUserMenu").hide();
 
76
                $("#popup").hide();
 
77
        });
79
78
});
80
79
 
81
 
window.onkeyup = function(event){
82
 
        if(event.keyCode==27){
83
 
                $('#formContainer').fadeOut(300);
84
 
                $('#passwordChanger').fadeOut(300);
85
 
                $('body *').animate({
86
 
                opacity:1}, 400);
87
 
                $('#changePassword')[0].reset();
88
 
        }
89
 
}
90
 
 
91
 
/* Closing password changer and reactivates body */
92
 
function cancelPasswordChange(){
93
 
        $('#passwordChanger').fadeOut(300);
94
 
        $('body *').animate({
95
 
        opacity:1}, 400);
96
 
        $('#changePassword')[0].reset();
97
 
}
98
 
 
99
 
 
100
 
/* Expand/Collapse courses in popout menu */
101
 
function expandCourses(){
102
 
        if(expandedCourses==0){
103
 
        $('#expandedCourses').stop(false, true).slideDown(300);
104
 
        expandedCourses=1;
105
 
        }
106
 
        else if(expandedCourses==1){
107
 
                $('#expandedCourses').stop(false, false).slideUp(300);  
108
 
                expandedCourses=0;
109
 
        }
110
 
}
111
 
 
 
80
function loginSubmit(e) {
 
81
        e.stopPropagation();
 
82
        e.preventDefault();
 
83
 
 
84
        var un = $(this).find("#username").val();
 
85
        var pw = $(this).find("#password").val();
 
86
 
 
87
        $.post(
 
88
                "start/login",
 
89
                { username: un, password: pw},
 
90
                function(data) {
 
91
                        if(data == "true") {
 
92
                                window.location.href ="./cms";
 
93
                        } else {
 
94
                                if($("#popup .popup").hasClass("error")) {
 
95
                                        $("#popup .popup form .errorContainer").html('Error! '+data+' Please try again.');
 
96
                                } else {
 
97
                                        $("#popup .popup").addClass("error");
 
98
                                        $("#popup .popup form").prepend('<div class="errorContainer">Error! '+data+' Please try again. </div>');
 
99
                                }
 
100
                        }
 
101
                }
 
102
        );
 
103
}
 
104
 
 
105
function loginHint(e) {
 
106
        e.preventDefault();
 
107
        e.stopPropagation();
 
108
 
 
109
        // If username field is empty, inform user and exit function
 
110
        var uname = $("#login #username").val();
 
111
        if(uname == "") {
 
112
                return;
 
113
        }
 
114
 
 
115
        // POST username to the function /ajax/pwdhint which returns a json object with password hint
 
116
        $.post(
 
117
                // Replace with final production URL!!!
 
118
 
 
119
                "ajax/pwdhint",
 
120
                // Data sent through POST
 
121
                { username: uname },
 
122
 
 
123
                // Callback function
 
124
                function(data) {
 
125
                        var result = $.parseJSON(data)["hint"];
 
126
 
 
127
                        // result["hint"] is either a boolean false or a string containing the hint
 
128
                        if(result === false) {
 
129
                                $("#hinttext").html('<p class="error">No password hint available</p>');
 
130
                        } else {
 
131
                                $("#hinttext").html('<p>Hint: ' + result + '</p>');
 
132
                        }
 
133
 
 
134
                        $("#login").toggleClass("expanded");
 
135
                        $("#hinttext").toggle();
 
136
 
 
137
                }
 
138
        ); // End $.post {}
 
139
 
 
140
} // End loginHint()
 
 
b'\\ No newline at end of file'