bzr branch
http://gegoxaren.bato24.eu/bzr/lenasys/trunk
|
52.1.1
by b11johgu
Added controllers for examplepage, templatelayout. |
1 |
/* Global variables */
|
2 |
var popoutMenu=0; |
|
3 |
var expandedCourses=0; |
|
4 |
||
5 |
/* Functions */
|
|
6 |
$(document).ready(function(){ |
|
7 |
$('#expandedCourses').hide(); |
|
8 |
$('#popoutMenu').hide(); |
|
9 |
$('#passwordChanger').hide(); |
|
10 |
||
11 |
||
12 |
/* Check courses in expanded menu */ |
|
13 |
$('li[class="expanded"]').click(function(){ |
|
14 |
if($(this).hasClass('checkedCourse')){ |
|
15 |
$(this).removeClass('checkedCourse'); |
|
16 |
} |
|
17 |
else{ |
|
18 |
$(this).addClass("checkedCourse"); |
|
19 |
} |
|
20 |
}); |
|
21 |
||
22 |
/* Blurs body and opens password changer */ |
|
23 |
$('li[name="changePwd"]').click(function(e){ |
|
24 |
e.stopPropagation(); |
|
25 |
$('#popoutMenu').stop(false, false).slideUp(300); |
|
26 |
popoutMenu=0; |
|
27 |
$('body *').not('#passwordChanger, #passwordChanger *').animate({ |
|
28 |
opacity:0.4}, 400); |
|
29 |
$('#passwordChanger').fadeIn(300); |
|
30 |
$('#passwordChanger').css('z-index', 3000); |
|
31 |
}); |
|
32 |
|
|
33 |
$('body').click(function(e){ |
|
34 |
$('#formContainer').fadeOut(300); |
|
35 |
$('#passwordChanger').fadeOut(300); |
|
36 |
$('body *').animate({ |
|
37 |
opacity:1}, 400); |
|
38 |
$('#changePassword')[0].reset(); |
|
39 |
}); |
|
40 |
|
|
41 |
$('#passwordChanger').click(function(e){ |
|
42 |
e.stopPropagation(); |
|
43 |
}); |
|
44 |
|
|
45 |
$('#formContainer').click(function(e){ |
|
46 |
e.stopPropagation(); |
|
47 |
}); |
|
48 |
|
|
49 |
$('#popoutLink').click(function(e){ |
|
50 |
if(popoutMenu==0){ |
|
51 |
$('#popoutMenu').stop(false, true).slideDown(300); |
|
52 |
popoutMenu=1; |
|
53 |
e.stopPropagation(); |
|
54 |
// FIXA SÅ MENYN INTE KOMMER UPP IGEN |
|
55 |
} |
|
56 |
else if(popoutMenu==1){ |
|
57 |
$('#popoutMenu').stop(false, false).slideUp(300); |
|
58 |
popoutMenu=0; |
|
59 |
e.stopPropagation(); |
|
60 |
} |
|
61 |
}); |
|
62 |
|
|
63 |
$('#loginLink').click(function(e){ |
|
64 |
var target = $('#formContainer'); |
|
65 |
if(target.is(":hidden")){ |
|
66 |
target.fadeIn(300); |
|
67 |
$('#username').focus(); |
|
68 |
e.stopPropagation(); |
|
69 |
} |
|
70 |
else{ |
|
71 |
target.fadeOut(300); |
|
72 |
} |
|
73 |
|
|
74 |
}); |
|
75 |
});
|
|
76 |
||
77 |
window.onkeyup = function(event){ |
|
78 |
if(event.keyCode==27){ |
|
79 |
$('#formContainer').fadeOut(300); |
|
80 |
$('#passwordChanger').fadeOut(300); |
|
81 |
$('body *').animate({ |
|
82 |
opacity:1}, 400); |
|
83 |
$('#changePassword')[0].reset(); |
|
84 |
} |
|
85 |
}
|
|
86 |
||
87 |
/* Closing password changer and reactivates body */
|
|
88 |
function cancelPasswordChange(){ |
|
89 |
$('#passwordChanger').fadeOut(300); |
|
90 |
$('body *').animate({ |
|
91 |
opacity:1}, 400); |
|
92 |
$('#changePassword')[0].reset(); |
|
93 |
}
|
|
94 |
||
95 |
||
96 |
/* Expand/Collapse courses in popout menu */
|
|
97 |
function expandCourses(){ |
|
98 |
if(expandedCourses==0){ |
|
99 |
$('#expandedCourses').stop(false, true).slideDown(300); |
|
100 |
expandedCourses=1; |
|
101 |
} |
|
102 |
else if(expandedCourses==1){ |
|
103 |
$('#expandedCourses').stop(false, false).slideUp(300); |
|
104 |
expandedCourses=0; |
|
105 |
} |
|
106 |
}
|
|
107 |
||
108 |
||
109 |
||
110 |
/* Password validation */
|
|
111 |
var acceptedNewPwd = false; |
|
112 |
var acceptedRepeatedPwd = false; |
|
113 |
||
114 |
function emptyField(inputId){ |
|
115 |
var id = document.getElementById(inputId); |
|
116 |
if(id.value.match(/^\s*$/)){ |
|
117 |
return true; |
|
118 |
} |
|
119 |
else return false; |
|
120 |
}
|
|
121 |
||
122 |
/* Checks input field for invalid characters */
|
|
123 |
function pwdValidCharacters(inputId){ |
|
124 |
var id = document.getElementById(inputId); |
|
125 |
if(id.value.match(/^[A-Öa-ö0-9 _]*[A-Öa-ö0-9][A-Öa-ö0-9 _]*$/)){ |
|
126 |
return true; |
|
127 |
} |
|
128 |
else return false; |
|
129 |
}
|
|
130 |
||
131 |
/* Checks input field for minimum amount of characters(6) */
|
|
132 |
function pwdMininumValue(inputId){ |
|
133 |
var id = document.getElementById(inputId); |
|
134 |
if(id.value.length > 5){ |
|
135 |
return true; |
|
136 |
} |
|
137 |
else return false; |
|
138 |
}
|
|
139 |
||
140 |
/* Checks if newPwd and repeatPwd are the same */
|
|
141 |
function pwdMatch(){ |
|
142 |
var firstPwd = document.getElementById("newPwd").value; |
|
143 |
var secondPwd = document.getElementById("repeatPwd").value; |
|
144 |
if(firstPwd == secondPwd){ |
|
145 |
return true; |
|
146 |
} |
|
147 |
else return false; |
|
148 |
}
|
|
149 |
||
150 |
function validNewPwd(){ |
|
151 |
var empty = emptyField("newPwd"); |
|
152 |
var validchar = pwdValidCharacters("newPwd"); |
|
153 |
var minimumchar = pwdMininumValue("newPwd"); |
|
154 |
||
155 |
if (empty==false && validchar==true && minimumchar==true){ |
|
156 |
document.getElementById("newPwd").className="Valid"; |
|
157 |
$('.errorMessage[name="newPwd"]').animate({opacity:0}, 0); |
|
158 |
acceptedNewPwd=true; |
|
159 |
} |
|
160 |
else if(empty==true){ |
|
161 |
acceptedNewPwd=false; |
|
162 |
document.getElementById("newPwd").className=""; |
|
163 |
$('.errorMessage[name="newPwd"]').animate({opacity:0}, 0); |
|
164 |
} |
|
165 |
else if(empty==false && validchar==false || minimumchar==false){ |
|
166 |
document.getElementById("newPwd").className="notValid"; |
|
167 |
$('.errorMessage[name="newPwd"]').animate({opacity:1}, 0); |
|
168 |
acceptedNewPwd=false; |
|
169 |
} |
|
170 |
}
|
|
171 |
||
172 |
function validRepeatedPwd(){ |
|
173 |
var empty = emptyField("repeatPwd"); |
|
174 |
var match = pwdMatch("repeatPwd"); |
|
175 |
|
|
176 |
if(validNewPwd){ |
|
177 |
if(empty==true){ |
|
178 |
document.getElementById("repeatPwd").className=""; |
|
179 |
$('.errorMessage[name="repeatPwd"]').animate({opacity:0}, 0); |
|
180 |
acceptedRepeatedPwd=false; |
|
181 |
} |
|
182 |
else if(empty==false && match==false){ |
|
183 |
document.getElementById("repeatPwd").className="notValid"; |
|
184 |
$('.errorMessage[name="repeatPwd"]').animate({opacity:1}, 0); |
|
185 |
acceptedRepeatedPwd=false; |
|
186 |
} |
|
187 |
else if(empty==false && match==true){ |
|
188 |
document.getElementById("repeatPwd").className="Valid"; |
|
189 |
$('.errorMessage[name="repeatPwd"]').animate({opacity:0}, 0); |
|
190 |
acceptedRepeatedPwd=true; |
|
191 |
} |
|
192 |
} |
|
193 |
else{ |
|
194 |
document.getElementById("repeatPwd").className=""; |
|
195 |
} |
|
196 |
}
|
|
197 |
||
198 |
/* baseURL skickas med som parameter */
|
|
199 |
function confirm(baseURL){ |
|
200 |
if(acceptedNewPwd && acceptedRepeatedPwd){ |
|
201 |
changePwd(baseURL); |
|
202 |
} |
|
203 |
else{ |
|
204 |
alert("WRONG WRONG WRONG!! FILL OUT THE FORM AGAIN YOU FKIN PIECE OF SHIT!"); |
|
205 |
return false; |
|
206 |
} |
|
207 |
}
|
|
208 |
||
209 |
function changePwd(baseURL) |
|
210 |
{
|
|
211 |
var currentPwd = document.getElementById("currentPwd").value; |
|
212 |
var newPwd = document.getElementById("newPwd").value; |
|
213 |
var hintPwd = document.getElementById("hintPwd").value; |
|
214 |
||
215 |
$.ajax({ |
|
216 |
type: 'POST', |
|
217 |
url: baseURL+'ajax/pwdchange', |
|
218 |
data: { |
|
219 |
currentPwd : currentPwd, |
|
220 |
newPwd : newPwd, |
|
221 |
hintPwd : hintPwd |
|
222 |
}, |
|
223 |
success: function(result){ |
|
224 |
var resultObject = JSON.parse(result); |
|
225 |
if(resultObject.status==true){ |
|
226 |
alert('Password change is successful!'); |
|
227 |
$('#formContainer').fadeOut(300); |
|
228 |
$('#passwordChanger').fadeOut(300); |
|
229 |
$('body *').animate({ |
|
230 |
opacity:1}, 400); |
|
231 |
$('#changePassword')[0].reset(); |
|
232 |
} |
|
233 |
else{ |
|
234 |
alert('Wrong password!'); |
|
235 |
} |
|
236 |
} |
|
237 |
}); |
|
238 |
}
|