Bases of survey edition interface.
[platal.git] / htdocs / javascript / xorg.js
CommitLineData
0337d704 1/***************************************************************************
5e1513f6 2 * Copyright (C) 2003-2011 Polytechnique.org *
0337d704 3 * http://opensource.polytechnique.org/ *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
20
350ba5ac 21var is_IE = $.browser.msie;
0337d704 22
23// {{{ function getNow()
80dcbd9a
FB
24var days = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
25var months = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
26 'août', 'septembre', 'octobre', 'novembre', 'décembre']
0337d704 27
0337d704 28function getNow() {
80dcbd9a
FB
29 var dt = new Date();
30 var dy = dt.getDay();
31 var mh = dt.getMonth();
32 var wd = dt.getDate();
33 var yr = dt.getYear();
0337d704 34 if (yr<1000) yr += 1900;
80dcbd9a
FB
35 var hr = dt.getHours();
36 var mi = dt.getMinutes();
37 if (mi < 10) {
38 mi = '0' + mi;
39 }
40 var se = dt.getSeconds();
41 if (se < 10) {
42 se = '0' + se;
43 }
9f449375 44
80dcbd9a
FB
45 $(".date-heure").html(days[dy] + ' ' + wd + ' ' + months[mh] + ' ' + yr + '<br />'
46 + hr + ':' + mi + ':' + se);
9f449375 47}
48
49// }}}
a27c6df8 50// {{{ Search Engine
51
52function canAddSearchEngine()
53{
350ba5ac
FB
54 if (((typeof window.sidebar == "object") && $.isFunction(window.sidebar.addSearchEngine))
55 || ((typeof window.external == "object") && $.isFunction(window.external.AddSearchProvider))) {
56 return true;
57 }
58 return false;
a27c6df8 59}
39fd8f50 60
b09e5dea 61function addSearchEngine()
62{
350ba5ac
FB
63 var searchURI = "http://www.polytechnique.org/xorg.opensearch.xml";
64 if ((typeof window.sidebar == "object") && $.isFunction(window.sidebar.addSearchEngine)) {
65 window.sidebar.addSearchEngine(
66 searchURI,
67 "http://www.polytechnique.org/images/xorg.png",
68 "Annuaire Polytechnique.org",
69 "Academic");
70 } else {
71 try {
72 window.external.AddSearchProvider(searchURI);
73 } catch(e) {
74 alert("Impossible d'installer la barre de recherche");
75 }
b09e5dea 76 }
39fd8f50 77}
78
39fd8f50 79// }}}
0337d704 80
81/***************************************************************************
82 * POPUP THINGS
83 */
84
769dc7d5
VZ
85// {{{ function goodiesPopup()
86
350ba5ac
FB
87var __goodies_active = true;
88
89var __goodies_ical = {
90 default_title: 'Calendrier iCal',
91 sites: [
92 {'url_prefix': '',
93 'img': 'images/icons/calendar_view_day.gif',
94 'title': 'Calendrier iCal'},
95 {'url_prefix': 'http://www.google.com/calendar/render?cid=',
96 'img': 'images/goodies/add-google-calendar.gif',
97 'title': 'Ajouter à Google Calendar'},
98 {'url_prefix': 'https://www.google.com/calendar/hosted/polytechnique.org/render?cid=',
99 'img': 'images/goodies/add-google-calendar.gif',
100 'title': 'Ajouter à Google Apps / Calendar'}
101 ]
102};
103
104var __goodies_rss = {
105 default_title: 'Fils RSS',
106 sites: [
107 {'url_prefix': '',
108 'img': 'images/icons/feed.gif',
109 'title': 'Fil rss'},
110 {'url_prefix': 'http://fusion.google.com/add?feedurl=',
111 'img': 'images/goodies/add-google.gif',
112 'alt': 'Add to Google',
113 'title': 'Ajouter à iGoogle/Google Reader'},
114 {'url_prefix': 'http://www.netvibes.com/subscribe.php?url=',
115 'img': 'images/goodies/add-netvibes.gif',
116 'title': 'Ajouter à Netvibes'},
117 {'url_prefix': 'http://add.my.yahoo.com/content?.intl=fr&url=',
118 'img': 'images/goodies/add-yahoo.gif',
119 'alt': 'Add to My Yahoo!',
cb143c01 120 'title': 'Ajouter à My Yahoo!'}
350ba5ac
FB
121 ]
122};
769dc7d5 123
f14eed3f
VZ
124function disableGoodiesPopups() {
125 __goodies_active = false;
126}
127
350ba5ac 128function goodiesPopup(node, goodies) {
769dc7d5 129 var text = '<div style="text-align: center; line-height: 2.2">';
350ba5ac
FB
130 for (var site in goodies.sites) {
131 var entry = goodies.sites[site];
132 var s_alt = entry["alt"] ? entry["alt"] : "";
133 var s_img = entry["img"];
134 var s_title = entry["title"] ? entry["title"] : "";
135 var s_url = entry["url_prefix"].length > 0 ? entry["url_prefix"] + escape(this.href) : this.href;
769dc7d5
VZ
136
137 text += '<a href="' + s_url + '"><img src="' + s_img + '" title="' + s_title + '" alt="' + s_alt + '"></a><br />';
138 }
350ba5ac 139 text += '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
769dc7d5 140
350ba5ac 141 var title = node.title ? node.title : goodies.default_title;
769dc7d5 142
350ba5ac
FB
143 $(node)
144 .mouseover(
145 function() {
146 if (__goodies_active) {
147 return overlib(text, CAPTION, title, CLOSETEXT, 'Fermer', DELAY, 800, STICKY, WIDTH, 150);
148 }
149 }
150 )
151 .mouseout(nd);
769dc7d5
VZ
152}
153
154// }}}
0337d704 155// {{{ function auto_links()
156
0337d704 157function auto_links() {
80dcbd9a
FB
158 var url = document.URL;
159 var fqdn = url.replace(/^https?:\/\/([^\/]*)\/.*$/,'$1');
160 var light = (url.indexOf('display=light') > url.indexOf('?'));
161 var resource_page = (url.indexOf('rss') > -1 || url.indexOf('ical') > -1);
e83d83e8 162
b804b882
FB
163 $("a,link").each(function(i) {
164 var node = $(this);
165 var href = this.href;
166 if(!href || node.hasClass('xdx')
167 || href.indexOf('mailto:') > -1 || href.indexOf('javascript:') > -1) {
168 return;
169 }
170 if ((href.indexOf(fqdn) < 0 && this.className.indexOf('popup') < 0) || node.hasClass('popup')) {
171 node.click(function () {
172 window.open(href);
173 return false;
174 });
175 }
176 if (href.indexOf(fqdn) > -1 && light) {
177 href = href.replace(/([^\#\?]*)\??([^\#]*)(\#.*)?/, "$1?display=light&$2$3");
178 this.href = href;
179 }
180 var rss = href.indexOf('rss') > -1;
181 var ical = href.indexOf('ical') > -1;
182 if (rss || ical) {
183 if (href.indexOf('http') < 0) {
184 href = 'http://' + fqdn + '/' + href;
e83d83e8 185 }
b804b882
FB
186 }
187 if (this.nodeName.toLowerCase() == 'a' && !resource_page) {
188 if (rss && href.indexOf('prefs/rss') < 0 && (href.indexOf('xml') > -1 || href.indexOf('hash'))) {
189 goodiesPopup(this, __goodies_rss);
190 } else if (ical) {
191 goodiesPopup(this, __goodies_ical);
769dc7d5 192 }
3def38d5 193 }
b804b882
FB
194 if(matches = (/^popup_([0-9]*)x([0-9]*)$/).exec(this.className)) {
195 var w = matches[1], h = matches[2];
196 node.popWin(w, h);
197 }
198 });
199 $('.popup2').popWin(840, 600);
200 $('.popup3').popWin(640, 800);
0337d704 201}
202
e83d83e8 203
0337d704 204// }}}
205
7143ad2b
FB
206/***************************************************************************
207 * Password check
208 */
209
210// {{{ function checkPassword
211
0ba43ee4
VZ
212function getType(c) {
213 if (c >= 'a' && c <= 'z') {
7143ad2b 214 return 1;
0ba43ee4 215 } else if (c >= 'A' && c <= 'Z') {
7143ad2b 216 return 2;
0ba43ee4 217 } else if (c >= '0' && c <= '9') {
7143ad2b
FB
218 return 3;
219 } else {
220 return 4;
221 }
222}
223
4baa7323 224function differentTypes(password) {
7143ad2b 225 var prev = 0;
4baa7323
SJ
226
227 for (i = 0 ; i < password.length ; ++i) {
228 var type = getType(password.charAt(i));
229 if (prev != 0 && prev != type) {
230 return true;
231 }
232 prev = type;
233 }
234 return false;
235}
236
237function passwordStrength(password) {
7143ad2b 238 var prop = 0;
4baa7323 239 var prev = 0;
eaa3f284 240 var firstType = true;
4baa7323
SJ
241 var types = Array(0, 0, 0, 0, 0);
242
243 for (i = 0 ; i < password.length ; ++i) {
244 var type = getType(password.charAt(i));
7143ad2b
FB
245 if (prev != 0 && prev != type) {
246 prop += 5;
4baa7323 247 firstType = false;
7143ad2b 248 }
eaa3f284
FB
249 prop += i;
250 if (types[type] == 0 && !firstType) {
251 prop += 15;
7143ad2b
FB
252 }
253 types[type]++;
254 prev = type;
255 }
4baa7323
SJ
256 if (password.length < 6) {
257 prop *= 0.75;
258 }
259 if (firstType) {
aca1582e 260 prop *= 0.75;
eaa3f284 261 }
7143ad2b
FB
262 if (prop > 100) {
263 prop = 100;
264 } else if (prop < 0) {
265 prop = 0;
266 }
4baa7323
SJ
267
268 return prop;
269}
270
271function checkPassword(box, okLabel) {
272 var password = box.value;
273 var prop = passwordStrength(password);
274
de99248c 275 if (prop >= 60) {
00681970
FB
276 color = "#4f4";
277 bgcolor = "#050";
de99248c 278 ok = true;
23f6d4cc 279 } else if (prop >= 35) {
de99248c 280 color = "#ff4";
00681970 281 bgcolor = "#750";
b19839fd 282 ok = true;
de99248c
FB
283 } else {
284 color = "#f20";
00681970 285 bgcolor = "#700";
de99248c
FB
286 ok = false;
287 }
288 $("#passwords_measure")
00681970
FB
289 .stop()
290 .animate({ width: prop + "%",
291 backgroundColor: color
292 }, 750)
293 .parent().stop()
294 .animate({ backgroundColor: bgcolor }, 750);
ed130f47 295 var submitButton = $(":submit[name='" + passwordprompt_submit + "']");
4baa7323 296 if (ok && password.length >= 6 && differentTypes(password)) {
7b7d0970 297 submitButton.attr("value", okLabel);
de99248c 298 submitButton.removeAttr("disabled");
7143ad2b 299 } else {
7b7d0970 300 submitButton.attr("value", "Mot de passe trop faible");
de99248c 301 submitButton.attr("disabled", "disabled");
7143ad2b
FB
302 }
303}
304
305// }}}
b0e935d6
FB
306// {{{ send test email
307
308function sendTestEmail(token, hruid)
309{
310 var url = 'emails/test';
311 var msg = "Un email a été envoyé avec succès";
312 if (hruid != null) {
313 url += '/' + hruid;
314 msg += " sur l'adresse de " + hruid + ".";
315 } else {
316 msg += " sur ton addresse.";
317 }
318 $('#mail_sent').successMessage($url + '?token=' + token, msg);
319 return false;
320}
321
322// }}}
7143ad2b
FB
323
324
0337d704 325/***************************************************************************
326 * The real OnLoad
327 */
328
4171c0bf 329$(function() {
80dcbd9a
FB
330 auto_links();
331 getNow();
332 setInterval(getNow, 1000);
333 $("#quick")
334 .focus(function() {
335 if ($(this).val() === 'Recherche dans l\'annuaire') {
336 $(this).val('');
337 }
338 $("#quick_button").show();
339 })
340 .blur(function() {
341 $("#quick_button").hide();
342 });
343 $("#quick_button").click(function() {
344 if ($("#quick").val() === 'Recherche dans l\'annuaire'
345 || $("#quick").val() === '') {
346 return false;
347 }
348 return true;
349 });
350});
0337d704 351
a14159bf 352// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: