MOD début du cleanage du code de euphorik.js
[euphorik.git] / js / euphorik.js
1 // coding: utf-8
2
3 /**
4 * Contient la base javascript pour le site euphorik.ch.
5 * Chaque page possède son propre fichier js nommé "page<nom de la page>.js".
6 * Auteur : GBurri
7 * Date : 6.11.2007
8 */
9
10 /**
11 * La configuration.
12 * Normalement 'const' à la place de 'var' mais non supporté par IE7.
13 */
14 var conf = {
15 nbMessageAffiche : 80, // (par page)
16 pseudoDefaut : "<nick>",
17 tempsAffichageMessageDialogue : 4000, // en ms
18 smiles : {
19 "smile" : [/:\)/g, /:-\)/g],
20 "bigsmile" : [/:D/g, /:-D/g],
21 "clin" : [/;\)/g, /;-\)/g],
22 "cool" : [/8\)/g, /8-\)/g],
23 "eheheh" : [/:P/g, /:-P/g],
24 "oh" : [/:o/g, /:O/g],
25 "pascontent" : [/>\(/g, /&gt;\(/g],
26 "sniff" : [/:\(/g, /:-\(/g],
27 "argn" : [/\[:argn\]/g],
28 "bunny" : [/\[:lapin\]/g],
29 "chat" : [/\[:chat\]/g],
30 "renne" : [/\[:renne\]/g],
31 "lol" : [/\[:lol\]/g],
32 "spliff" : [/\[:spliff\]/g],
33 "star" : [/\[:star\]/g],
34 "triste" : [/\[:triste\]/g],
35 "kirby" : [/\[:kirby\]/g]
36 }
37 }
38
39 ///////////////////////////////////////////////////////////////////////////////////////////////////
40
41 String.prototype.trim = function()
42 {
43 return this.replace(/^\s+|\s+$/g, "");
44 }
45
46 String.prototype.ltrim = function()
47 {
48 return this.replace(/^\s+/, "");
49 }
50
51 String.prototype.rtrim = function()
52 {
53 return this.replace(/\s+$/, "");
54 }
55
56 String.prototype.dump = function()
57 {
58 if (typeof dump != "undefined")
59 {
60 dump("\n--- EUPHORIK.CH ---\n")
61 dump(this)
62 dump("\n------\n")
63 }
64 }
65
66 ///////////////////////////////////////////////////////////////////////////////////////////////////
67
68 /**
69 * Cette classe regroupe des fonctions utilitaires (helpers).
70 */
71 function Util()
72 {
73 if(typeof XMLSerializer != "undefined")
74 this.serializer = new XMLSerializer()
75
76 // fermeture des dialogues d
77 jQuery("#info .fermer").click(function(){
78 jQuery("#info").slideUp(50)
79 })
80 }
81
82 /**
83 * Affiche une boite de dialogue avec un message à l'intérieur.
84 * @param message le message (string)
85 * @param type voir 'messageType'. par défaut messageType.informatif
86 * @param les boutons sous la forme d'un objet ou les clefs sont les labels des boutons
87 * et les valeurs les fonctions executées lorsqu'un bouton est activé.
88 */
89 Util.prototype.messageDialogue = function(message, type, boutons)
90 {
91 if (type == undefined)
92 type = messageType.informatif
93
94 if (this.timeoutMessageDialogue != undefined)
95 clearTimeout(this.timeoutMessageDialogue)
96
97 var fermer = function(){jQuery("#info").slideUp(100)}
98 fermer()
99
100 jQuery("#info .message").html(message)
101 switch(type)
102 {
103 case messageType.informatif : jQuery("#info #icone").attr("class", "information"); break
104 case messageType.question : jQuery("#info #icone").attr("class", "interrogation"); break
105 case messageType.erreur : jQuery("#info #icone").attr("class", "exclamation"); break
106 }
107 jQuery("#info .boutons").html("")
108 for (var b in boutons)
109 jQuery("#info .boutons").append("<div>" + b + "</div>").find("div:last").click(boutons[b]).click(fermer)
110
111 jQuery("#info").slideDown(200)
112 this.timeoutMessageDialogue = setTimeout(fermer, conf.tempsAffichageMessageDialogue)
113 }
114 var messageType = {informatif: 0, question: 1, erreur: 2}
115
116 /**
117 * Transforme un document XML en string.
118 */
119 Util.prototype.serializeXML = function(documentXML)
120 {
121 if (this.serializer)
122 return this.serializer.serializeToString(documentXML)
123 else
124 return documentXML.xml
125 }
126
127 Util.prototype.creerDocumentXMLAction = function()
128 {
129 if (document.implementation && document.implementation.createDocument)
130 {
131 return document.implementation.createDocument("", "action", null)
132 }
133 else if (window.ActiveXObject)
134 {
135 var doc = new ActiveXObject("MSXML2.DOMDocument") //("Microsoft.XMLDOM")
136 doc.appendChild(doc.createElement("action"));
137 //doc.loadXML("<action></action>")
138 //alert(doc.documentElement)
139 //doc.createElement("action")
140 return doc
141 }
142 }
143
144 Util.prototype.xmlVersAction = function(xml)
145 {
146 return {action: this.to_utf8(this.serializeXML(xml /*, "UTF-8"*/))}
147 }
148
149 // voir : http://homepage3.nifty.com/aokura/jscript/utf8.html
150 // et : http://www1.tip.nl/~t876506/utf8tbl.html
151 Util.prototype.to_utf8 = function(s)
152 {
153 if (!s) return ""
154
155 var c, d = ""
156 for (var i = 0; i < s.length; i++)
157 {
158 c = s.charCodeAt(i);
159 if (c <= 0x7f) {
160 d += s.charAt(i);
161 } else if (c >= 0x80 && c <= 0x7ff) {
162 d += String.fromCharCode(((c >> 6) & 0x1f) | 0xc0);
163 d += String.fromCharCode((c & 0x3f) | 0x80);
164 } else {
165 d += String.fromCharCode((c >> 12) | 0xe0);
166 d += String.fromCharCode(((c >> 6) & 0x3f) | 0x80);
167 d += String.fromCharCode((c & 0x3f) | 0x80);
168 }
169 }
170 return d;
171 }
172
173 Util.prototype.md5 = function(chaine)
174 {
175 return hex_md5(chaine)
176 }
177
178 // pompé de http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130
179 Util.prototype.setSelectionRange = function(input, selectionStart, selectionEnd)
180 {
181 if (input.setSelectionRange)
182 {
183 input.focus()
184 input.setSelectionRange(selectionStart, selectionEnd)
185 }
186 else if (input.createTextRange)
187 {
188 var range = input.createTextRange()
189 range.collapse(true)
190 range.moveEnd('character', selectionEnd)
191 range.moveStart('character', selectionStart)
192 range.select()
193 }
194 }
195
196 Util.prototype.setCaretToEnd = function(input)
197 {
198 this.setSelectionRange(input, input.value.length, input.value.length)
199 }
200 Util.prototype.setCaretToBegin = function(input)
201 {
202 this.setSelectionRange(input, 0, 0)
203 }
204 Util.prototype.setCaretToPos = function(input, pos)
205 {
206 this.setSelectionRange(input, pos, pos)
207 }
208 Util.prototype.selectString = function(input, string)
209 {
210 var match = new RegExp(string, "i").exec(input.value)
211 if (match)
212 {
213 this.setSelectionRange (input, match.index, match.index + match[0].length)
214 }
215 }
216 Util.prototype.replaceSelection = function(input, replaceString) {
217 if (input.setSelectionRange)
218 {
219 var selectionStart = input.selectionStart
220 var selectionEnd = input.selectionEnd
221 input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd)
222
223 if (selectionStart != selectionEnd) // has there been a selection
224 this.setSelectionRange(input, selectionStart, selectionStart + replaceString.length)
225 else // set caret
226 this.setCaretToPos(input, selectionStart + replaceString.length)
227 }
228 else if (document.selection)
229 {
230 var range = document.selection.createRange();
231 if (range.parentElement() == input)
232 {
233 var isCollapsed = range.text == ''
234 range.text = replaceString
235 if (!isCollapsed)
236 {
237 // there has been a selection
238 // it appears range.select() should select the newly
239 // inserted text but that fails with IE
240 range.moveStart('character', -replaceString.length);
241 range.select();
242 }
243 }
244 }
245 }
246
247 ///////////////////////////////////////////////////////////////////////////////////////////////////
248
249 function Pages()
250 {
251 this.pageCourante = null
252 this.pages = {}
253 }
254
255 Pages.prototype.ajouterPage = function(page)
256 {
257 page.pages = this // la magie des langages dynamiques : le foutoire
258 this.pages[page.nom] = page
259 }
260
261 Pages.prototype.afficherPage = function(nomPage, forcerChargement)
262 {
263 if (forcerChargement == undefined) forcerChargement = false
264
265 var page = this.pages[nomPage]
266 if (page == undefined || (!forcerChargement && page == this.pageCourante)) return
267
268 if (this.pageCourante != null && this.pageCourante.decharger)
269 this.pageCourante.decharger()
270
271 jQuery("#menu div").removeClass("courante")
272 jQuery("#menu div." + nomPage).addClass("courante")
273
274 this.pageCourante = page
275 jQuery("#page").html(this.pageCourante.contenu()).removeClass().addClass(this.pageCourante.nom)
276
277 if (this.pageCourante.charger)
278 this.pageCourante.charger()
279 }
280
281 ///////////////////////////////////////////////////////////////////////////////////////////////////
282
283 function Formateur()
284 {
285 this.smiles = conf.smiles
286 this.protocoles = "http|https|ed2k"
287
288 this.regexUrl = new RegExp("(?:(?:" + this.protocoles + ")://|www\\.)[^ ]*", "gi")
289 this.regexImg = new RegExp("^.*?\\.(gif|jpg|png|jpeg|bmp|tiff)$", "i")
290 this.regexDomaine = new RegExp("^(?:(?:" + this.protocoles + ")://|www\\.).*?([^/.]+\\.[^/.]+)(?:$|/).*$", "i")
291 this.regexTestProtocoleExiste = new RegExp("^(?:" + this.protocoles + ")://.*$", "i")
292 this.regexNomProtocole = new RegExp("^(.*?)://")
293 }
294
295 /**
296 * Formate un pseudo saise par l'utilisateur.
297 * @param pseudo le pseudo brut
298 * @return le pseudo filtré
299 */
300 Formateur.prototype.filtrerInputPseudo = function(pseudo)
301 {
302 return pseudo.replace(/{|}/g, "").trim()
303 }
304
305 Formateur.prototype.getSmilesHTML = function()
306 {
307 var XHTML = ""
308 for (var sNom in this.smiles)
309 {
310 XHTML += "<img class=\"" + sNom + "\" src=\"img/smileys/" + sNom + ".gif\" />"
311 }
312 return XHTML
313 }
314
315 Formateur.prototype.traitementComplet = function(M, pseudo)
316 {
317 return this.traiterSmiles(this.traiterURL(this.remplacerBalisesHTML(M), pseudo))
318 }
319
320 /**
321 * FIXME : Cette méthode est attrocement lourde !!
322 */
323 Formateur.prototype.traiterSmiles = function(M)
324 {
325 for (var sNom in this.smiles)
326 {
327 ss = this.smiles[sNom]
328 for (var i = 0; i < ss.length; i++)
329 M = M.replace(ss[i], "<img src=\"img/smileys/" + sNom + ".gif\" />")
330 }
331 return M
332 }
333
334 Formateur.prototype.remplacerBalisesHTML = function(M)
335 {
336 return M.replace(/</g, "&lt;").replace(/>/g, "&gt;")
337 }
338
339 Formateur.prototype.traiterURL = function(M, pseudo)
340 {
341 thisFormateur = this
342
343 if (pseudo == undefined)
344 pseudo = ""
345
346 var traitementUrl = function(url)
347 {
348 // si ya pas de protocole on rajoute "http://"
349 if (!thisFormateur.regexTestProtocoleExiste.test(url))
350 url = "http://" + url
351 var extension = thisFormateur.getShort(url)
352 return "<a " + (extension[1] ? "title=\"" + thisFormateur.traiterPourFenetreLightBox(pseudo, url) + ": " + thisFormateur.traiterPourFenetreLightBox(M, url) + "\"" + " rel=\"lightbox[groupe]\"" : "") + " href=\"" + url + "\" >[" + extension[0] + "]</a>"
353 }
354 return M.replace(this.regexUrl, traitementUrl)
355 }
356
357 /**
358 * Renvoie une version courte de l'url.
359 * par exemple : http://en.wikipedia.org/wiki/Yakov_Smirnoff devient wikipedia.org
360 */
361 Formateur.prototype.getShort = function(url)
362 {
363 var estUneImage = false
364 var versionShort = null
365 var rechercheImg = this.regexImg.exec(url)
366 //alert(url)
367 if (rechercheImg != null)
368 {
369 versionShort = rechercheImg[1].toLowerCase()
370 if (versionShort == "jpeg") versionShort = "jpg" // jpeg -> jpg
371 estUneImage = true
372 }
373 else
374 {
375 var rechercheDomaine = this.regexDomaine.exec(url)
376 if (rechercheDomaine != null && rechercheDomaine.length >= 2)
377 versionShort = rechercheDomaine[1]
378 else
379 {
380 var nomProtocole = this.regexNomProtocole.exec(url)
381 if (nomProtocole != null && nomProtocole.length >= 2)
382 versionShort = nomProtocole[1]
383 }
384 }
385
386 return [versionShort == null ? "url" : versionShort, estUneImage]
387 }
388
389 /**
390 * Traite les pseudo et messages à être affiché dans le titre d'une image visualisé avec lightbox.
391 */
392 Formateur.prototype.traiterPourFenetreLightBox = function(M, urlCourante)
393 {
394 thisFormateur = this
395 var traitementUrl = function(url)
396 {
397 return "[" + thisFormateur.getShort(url)[0] + (urlCourante == url ? ": image courante" : "") + "]"
398 }
399
400 return this.remplacerBalisesHTML(M).replace(this.regexUrl, traitementUrl)
401 }
402
403
404 ///////////////////////////////////////////////////////////////////////////////////////////////////
405
406 var statutType = {enregistre: 0, identifie: 1, non_identifie: 2}
407
408 function Client(util)
409 {
410 this.util = util
411
412 this.cookie = null
413 this.regexCookie = new RegExp("^cookie=([^;]*)")
414
415 // Obsolète
416 //this.captchaCrypt = null
417
418 // données personnels
419 this.resetDonneesPersonnelles()
420
421 this.setStatut(statutType.non_identifie)
422
423 // le dernier message d'erreur recut du serveur (par exemple une connexion foireuse : "login impossible")
424 this.dernierMessageErreur = ""
425 }
426
427 Client.prototype.resetDonneesPersonnelles = function()
428 {
429 this.pseudo = conf.pseudoDefaut
430 this.login = ""
431 this.password = ""
432 this.email = ""
433 this.css = jQuery("link#cssPrincipale").attr("href")
434 }
435
436 Client.prototype.setCss = function(css)
437 {
438 if (this.css == css)
439 return
440
441 this.css = css
442 jQuery("link#cssPrincipale").attr("href", this.css)
443 this.majMenu()
444
445 /* enregistement automatique..
446 if (!this.identifie())
447 if (!this.enregistrement())
448 return
449 */
450 if (this.identifie())
451 this.flush()
452 }
453
454 Client.prototype.getXMLlogin = function(login, password)
455 {
456 var XMLDocument = this.util.creerDocumentXMLAction()
457 XMLDocument.documentElement.setAttribute("name", "login")
458
459 var nodeLogin = XMLDocument.createElement("login")
460 nodeLogin.appendChild(XMLDocument.createTextNode(login))
461 XMLDocument.documentElement.appendChild(nodeLogin)
462
463 var nodePassword = XMLDocument.createElement("password")
464 nodePassword.appendChild(XMLDocument.createTextNode(password))
465 XMLDocument.documentElement.appendChild(nodePassword)
466
467 return XMLDocument
468 }
469
470 Client.prototype.getXMLloginCookie = function()
471 {
472 var XMLDocument = this.util.creerDocumentXMLAction()
473 XMLDocument.documentElement.setAttribute("name", "login")
474
475 var nodeCookie = XMLDocument.createElement("cookie")
476 nodeCookie.appendChild(XMLDocument.createTextNode(this.cookie))
477 XMLDocument.documentElement.appendChild(nodeCookie)
478
479 return XMLDocument
480 }
481
482 /* Obsolète
483 Client.prototype.getXMLloginCaptcha = function(captchaCrypt, captchaInput)
484 {
485 var XMLDocument = this.util.creerDocumentXMLAction()
486 XMLDocument.documentElement.setAttribute("name", "loginCaptcha")
487
488 var nodecaptchaCrypt = XMLDocument.createElement("captchaCrypt")
489 nodecaptchaCrypt.appendChild(XMLDocument.createTextNode(captchaCrypt))
490 XMLDocument.documentElement.appendChild(nodecaptchaCrypt)
491
492 var nodecaptchaInput = XMLDocument.createElement("captchaInput")
493 nodecaptchaInput.appendChild(XMLDocument.createTextNode(captchaInput))
494 XMLDocument.documentElement.appendChild(nodecaptchaInput)
495
496 return XMLDocument
497 }*/
498
499 /* Obsolète
500 Client.prototype.getXMLgenerationCaptcha = function()
501 {
502 var XMLDocument = this.util.creerDocumentXMLAction()
503 XMLDocument.documentElement.setAttribute("name", "generationCaptcha")
504
505 return XMLDocument
506 }*/
507
508 Client.prototype.getXMLEnregistrement = function(login, password)
509 {
510 var XMLDocument = this.util.creerDocumentXMLAction()
511 XMLDocument.documentElement.setAttribute("name", "register")
512
513 var nodeLogin = XMLDocument.createElement("login")
514 nodeLogin.appendChild(XMLDocument.createTextNode(login))
515 XMLDocument.documentElement.appendChild(nodeLogin)
516
517 var nodePassword = XMLDocument.createElement("password")
518 nodePassword.appendChild(XMLDocument.createTextNode(password))
519 XMLDocument.documentElement.appendChild(nodePassword)
520
521 return XMLDocument
522 }
523
524 Client.prototype.getXMLProfile = function()
525 {
526 var XMLDocument = this.util.creerDocumentXMLAction()
527 XMLDocument.documentElement.setAttribute("name", "profile")
528
529 var nodeCookie = XMLDocument.createElement("cookie")
530 nodeCookie.appendChild(XMLDocument.createTextNode(this.cookie))
531 XMLDocument.documentElement.appendChild(nodeCookie)
532
533 var nodeLogin = XMLDocument.createElement("login")
534 nodeLogin.appendChild(XMLDocument.createTextNode(this.login))
535 XMLDocument.documentElement.appendChild(nodeLogin)
536
537 var nodePassword = XMLDocument.createElement("password")
538 nodePassword.appendChild(XMLDocument.createTextNode(this.password))
539 XMLDocument.documentElement.appendChild(nodePassword)
540
541 var nodePseudo = XMLDocument.createElement("pseudo")
542 nodePseudo.appendChild(XMLDocument.createTextNode(this.pseudo))
543 XMLDocument.documentElement.appendChild(nodePseudo)
544
545 var nodeEmail = XMLDocument.createElement("email")
546 nodeEmail.appendChild(XMLDocument.createTextNode(this.email))
547 XMLDocument.documentElement.appendChild(nodeEmail)
548
549 var nodeCSS = XMLDocument.createElement("css")
550 nodeCSS.appendChild(XMLDocument.createTextNode(this.css))
551 XMLDocument.documentElement.appendChild(nodeCSS)
552
553 return XMLDocument
554 }
555
556 /**
557 * Renvoie null si pas définit.
558 */
559 Client.prototype.getCookie = function()
560 {
561 var cookie = this.regexCookie.exec(document.cookie)
562 if (cookie == null) this.cookie = null
563 else this.cookie = cookie[1]
564 }
565
566 Client.prototype.delCookie = function()
567 {
568 document.cookie = "cookie=; max-age=0"
569 }
570
571 Client.prototype.setCookie = function(cookie)
572 {
573 if (this.cookie == null)
574 return
575
576 document.cookie =
577 "cookie="+this.cookie+
578 "; max-age=" + (60 * 60 * 24 * 365)
579 }
580
581 Client.prototype.identifie = function()
582 {
583 return this.statut == statutType.enregistre || this.statut == statutType.identifie
584 }
585
586 Client.prototype.setStatut = function(statut)
587 {
588 if(typeof(statut) == "string")
589 {
590 statut =
591 statut == "enregistre" ?
592 statutType.enregistre : (statut == "identifie" ? statutType.identifie : statutType.non_identifie)
593 }
594
595 if (statut == this.statut) return
596
597 this.statut = statut
598 this.majMenu()
599 }
600
601 /**
602 * Demande la génération d'un captcha au serveur et l'affiche.
603 */
604 /* Obsolète
605 Client.prototype.afficherCaptcha = function(query)
606 {
607 var thisClient = this
608
609 $.post("request", this.util.xmlVersAction(this.getXMLgenerationCaptcha()),
610 function(data, textStatus)
611 {
612 var chemin = jQuery("chemin", data.documentElement).text()
613 thisClient.captchaCrypt = jQuery("captchaCrypt", data.documentElement).text()
614 jQuery(query).prepend(
615 "<p id=\"captcha\" >Es-tu un bot ? <img class=\"captchaImg\" src=\"" + chemin + "\" />" +
616 "<input name=\"captchaInput\" type=\"text\" size=\"5\" max_length=\"5\" ></p>"
617 )
618 }
619 )
620 }
621
622 Client.prototype.cacherCaptcha = function()
623 {
624 jQuery("#captcha").remove()
625 }*/
626
627 /**
628 * Effectue la connexion vers le serveur.
629 * Cette fonction est bloquante tant que la connexion n'a pas été établie.
630 * S'il existe un cookie en local on s'authentifie directement avec lui.
631 * Si il n'est pas possible de s'authentifier alors on affiche un captcha anti-bot.
632 */
633 Client.prototype.connexionCookie = function()
634 {
635 this.getCookie()
636 if (this.cookie == null) return false;
637 return this.connexion(this.util.xmlVersAction(this.getXMLloginCookie()))
638 }
639
640 Client.prototype.connexionLogin = function(login, password)
641 {
642 return this.connexion(this.util.xmlVersAction(this.getXMLlogin(login, password)))
643 }
644
645 /* Obsolète
646 Client.prototype.connexionCaptcha = function()
647 {
648 return this.connexion(this.util.xmlVersAction(this.getXMLloginCaptcha(this.captchaCrypt, jQuery("#captcha input").val())))
649 }*/
650
651 Client.prototype.enregistrement = function(login, password)
652 {
653 if (this.identifie())
654 {
655 this.login = login
656 this.password = password
657 if(this.flush())
658 this.setStatut(statutType.enregistre)
659 return true
660 }
661 else
662 {
663 if (login == undefined) login = ""
664 if (password == undefined) password = ""
665 return this.connexion(this.util.xmlVersAction(this.getXMLEnregistrement(login, password)))
666 }
667 }
668
669 Client.prototype.connexion = function(action)
670 {
671 thisClient = this
672 jQuery.ajax(
673 {
674 async: false,
675 type: "POST",
676 url: "request",
677 dataType: "xml",
678 data: action,
679 success:
680 function(data)
681 {
682 thisClient.chargerDonnees(data)
683 }
684 }
685 )
686 return this.identifie()
687 }
688
689 Client.prototype.deconnexion = function()
690 {
691 this.setStatut(statutType.non_identifie) // deconnexion
692 this.resetDonneesPersonnelles()
693 this.delCookie ()
694 }
695
696 Client.prototype.chargerDonnees = function(data)
697 {
698 this.setStatut(jQuery("statut", data.documentElement).text())
699
700 if (this.identifie())
701 {
702 this.cookie = jQuery("cookie", data.documentElement).text()
703 this.setCookie()
704
705 this.login = jQuery("login", data.documentElement).text()
706 this.pseudo = jQuery("pseudo", data.documentElement).text()
707 this.email = jQuery("email", data.documentElement).text()
708 this.css = jQuery("css", data.documentElement).text()
709 // met à jour la css
710 if (this.css != "")
711 {
712 jQuery("link#cssPrincipale").attr("href", this.css)
713 this.majMenu()
714 }
715 }
716 this.dernierMessageErreur = jQuery("information", data.documentElement).text()
717 }
718
719 /**
720 * Met à jour les données personne sur serveur.
721 */
722 Client.prototype.flush = function()
723 {
724 thisClient = this
725 //thisClient.util.log(this.util.xmlVersAction(this.getXMLProfile()).action)
726 jQuery.ajax(
727 {
728 async: true,
729 type: "POST",
730 url: "request",
731 dataType: "xml",
732 data: this.util.xmlVersAction(this.getXMLProfile()),
733 success:
734 function(data)
735 {
736 //thisClient.util.log(thisClient.util.serializer.serializeToString(data))
737 }
738 }
739 )
740 // TODO : retourner false si un problème est survenu lors de l'update du profile
741 return true
742 }
743
744 Client.prototype.majMenu = function()
745 {
746 var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client
747
748 // met à jour le menu
749 if (this.statut == statutType.enregistre)
750 {
751 jQuery("#menu .profile").css("display", displayType).text("profile")
752 jQuery("#menu .logout").css("display", displayType)
753 jQuery("#menu .register").css("display", "none")
754 }
755 else if (this.statut == statutType.identifie)
756 {
757 jQuery("#menu .profile").css("display", "none")
758 jQuery("#menu .logout").css("display", displayType)
759 jQuery("#menu .register").css("display", displayType)
760 }
761 else
762 {
763 jQuery("#menu .profile").css("display", displayType).text("login")
764 jQuery("#menu .logout").css("display", "none")
765 jQuery("#menu .register").css("display", displayType)
766 }
767 }
768
769 ///////////////////////////////////////////////////////////////////////////////////////////////////
770
771 jQuery.noConflict()
772
773
774 // le main
775 jQuery(document).ready(
776 function()
777 {
778 var util = new Util()
779 var client = new Client(util)
780 var pages = new Pages()
781 var formateur = new Formateur()
782
783 // connexion vers le serveur (utilise un cookie qui traine)
784 client.connexionCookie()
785
786 // les styles css
787 for (var i = 1; i <= 3; i++)
788 {
789 jQuery("#css"+i).click(function(){
790 client.setCss("css/" + jQuery(this).attr("id").charAt(3) + "/euphorik.css")
791 })
792 }
793
794 jQuery("#menu .minichat").click(function(){ pages.afficherPage("minichat") })
795 jQuery("#menu .profile").click(function(){ pages.afficherPage("profile") })
796 jQuery("#menu .logout").click(function(){
797 util.messageDialogue("Êtes-vous sur de vouloir vous délogger ?", messageType.question,
798 {"Oui" : function()
799 {
800 client.deconnexion();
801 pages.afficherPage("minichat", true)
802 },
803 "Non" : function(){}
804 }
805 )
806 })
807 jQuery("#menu .register").click(function(){ pages.afficherPage("register") })
808
809 pages.ajouterPage(new PageMinichat(client, formateur, util))
810 pages.ajouterPage(new PageProfile(client, formateur, util))
811 pages.ajouterPage(new PageRegister(client, formateur, util))
812 pages.afficherPage("minichat")
813 }
814 )
815