ADD support des conversations (pas fini)
[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 // var doc = document.implementation.createDocument("", "action", null)
132 var parser = new DOMParser();
133 var doc = parser.parseFromString("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<action/>", "text/xml")
134 //alert(this.serializeXML(doc))
135 return doc
136 }
137 else if (window.ActiveXObject)
138 {
139 var doc = new ActiveXObject("MSXML2.DOMDocument") //("Microsoft.XMLDOM")
140 doc.appendChild(doc.createElement("action"));
141 //doc.loadXML("<action></action>")
142 //alert(doc.documentElement)
143 //doc.createElement("action")
144 return doc
145 }
146 }
147
148 Util.prototype.xmlVersAction = function(xml)
149 {
150 //return {action: this.to_utf8(this.serializeXML(xml /*, "UTF-8"*/))}
151 return {action: this.serializeXML(xml)}
152 }
153
154 Util.prototype.md5 = function(chaine)
155 {
156 return hex_md5(chaine)
157 }
158
159 // pompé de http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130
160 Util.prototype.setSelectionRange = function(input, selectionStart, selectionEnd)
161 {
162 if (input.setSelectionRange)
163 {
164 input.focus()
165 input.setSelectionRange(selectionStart, selectionEnd)
166 }
167 else if (input.createTextRange)
168 {
169 var range = input.createTextRange()
170 range.collapse(true)
171 range.moveEnd('character', selectionEnd)
172 range.moveStart('character', selectionStart)
173 range.select()
174 }
175 }
176
177 Util.prototype.setCaretToEnd = function(input)
178 {
179 this.setSelectionRange(input, input.value.length, input.value.length)
180 }
181 Util.prototype.setCaretToBegin = function(input)
182 {
183 this.setSelectionRange(input, 0, 0)
184 }
185 Util.prototype.setCaretToPos = function(input, pos)
186 {
187 this.setSelectionRange(input, pos, pos)
188 }
189 Util.prototype.selectString = function(input, string)
190 {
191 var match = new RegExp(string, "i").exec(input.value)
192 if (match)
193 {
194 this.setSelectionRange (input, match.index, match.index + match[0].length)
195 }
196 }
197 Util.prototype.replaceSelection = function(input, replaceString) {
198 if (input.setSelectionRange)
199 {
200 var selectionStart = input.selectionStart
201 var selectionEnd = input.selectionEnd
202 input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd)
203
204 if (selectionStart != selectionEnd) // has there been a selection
205 this.setSelectionRange(input, selectionStart, selectionStart + replaceString.length)
206 else // set caret
207 this.setCaretToPos(input, selectionStart + replaceString.length)
208 }
209 else if (document.selection)
210 {
211 var range = document.selection.createRange();
212 if (range.parentElement() == input)
213 {
214 var isCollapsed = range.text == ''
215 range.text = replaceString
216 if (!isCollapsed)
217 {
218 // there has been a selection
219 // it appears range.select() should select the newly
220 // inserted text but that fails with IE
221 range.moveStart('character', -replaceString.length);
222 range.select();
223 }
224 }
225 }
226 }
227
228 ///////////////////////////////////////////////////////////////////////////////////////////////////
229
230 function Pages()
231 {
232 this.pageCourante = null
233 this.pages = {}
234 }
235
236 Pages.prototype.ajouterPage = function(page)
237 {
238 page.pages = this // la magie des langages dynamiques : le foutoire
239 this.pages[page.nom] = page
240 }
241
242 Pages.prototype.afficherPage = function(nomPage, forcerChargement)
243 {
244 if (forcerChargement == undefined) forcerChargement = false
245
246 var page = this.pages[nomPage]
247 if (page == undefined || (!forcerChargement && page == this.pageCourante)) return
248
249 if (this.pageCourante != null && this.pageCourante.decharger)
250 this.pageCourante.decharger()
251
252 jQuery("#menu div").removeClass("courante")
253 jQuery("#menu div." + nomPage).addClass("courante")
254
255 this.pageCourante = page
256 jQuery("#page").html(this.pageCourante.contenu()).removeClass().addClass(this.pageCourante.nom)
257
258 if (this.pageCourante.charger)
259 this.pageCourante.charger()
260 }
261
262 ///////////////////////////////////////////////////////////////////////////////////////////////////
263
264 function Formateur()
265 {
266 this.smiles = conf.smiles
267 this.protocoles = "http|https|ed2k"
268
269 this.regexUrl = new RegExp("(?:(?:" + this.protocoles + ")://|www\\.)[^ ]*", "gi")
270 this.regexImg = new RegExp("^.*?\\.(gif|jpg|png|jpeg|bmp|tiff)$", "i")
271 this.regexDomaine = new RegExp("^(?:(?:" + this.protocoles + ")://|www\\.).*?([^/.]+\\.[^/.]+)(?:$|/).*$", "i")
272 this.regexTestProtocoleExiste = new RegExp("^(?:" + this.protocoles + ")://.*$", "i")
273 this.regexNomProtocole = new RegExp("^(.*?)://")
274 }
275
276 /**
277 * Formate un pseudo saise par l'utilisateur.
278 * @param pseudo le pseudo brut
279 * @return le pseudo filtré
280 */
281 Formateur.prototype.filtrerInputPseudo = function(pseudo)
282 {
283 return pseudo.replace(/{|}/g, "").trim()
284 }
285
286 Formateur.prototype.getSmilesHTML = function()
287 {
288 var XHTML = ""
289 for (var sNom in this.smiles)
290 {
291 XHTML += "<img class=\"" + sNom + "\" src=\"img/smileys/" + sNom + ".gif\" />"
292 }
293 return XHTML
294 }
295
296 Formateur.prototype.traitementComplet = function(M, pseudo)
297 {
298 return this.traiterSmiles(this.traiterURL(this.remplacerBalisesHTML(M), pseudo))
299 }
300
301 /**
302 * FIXME : Cette méthode est attrocement lourde !!
303 */
304 Formateur.prototype.traiterSmiles = function(M)
305 {
306 for (var sNom in this.smiles)
307 {
308 ss = this.smiles[sNom]
309 for (var i = 0; i < ss.length; i++)
310 M = M.replace(ss[i], "<img src=\"img/smileys/" + sNom + ".gif\" />")
311 }
312 return M
313 }
314
315 Formateur.prototype.remplacerBalisesHTML = function(M)
316 {
317 return M.replace(/</g, "&lt;").replace(/>/g, "&gt;")
318 }
319
320 Formateur.prototype.traiterURL = function(M, pseudo)
321 {
322 thisFormateur = this
323
324 if (pseudo == undefined)
325 pseudo = ""
326
327 var traitementUrl = function(url)
328 {
329 // si ya pas de protocole on rajoute "http://"
330 if (!thisFormateur.regexTestProtocoleExiste.test(url))
331 url = "http://" + url
332 var extension = thisFormateur.getShort(url)
333 return "<a " + (extension[1] ? "title=\"" + thisFormateur.traiterPourFenetreLightBox(pseudo, url) + ": " + thisFormateur.traiterPourFenetreLightBox(M, url) + "\"" + " rel=\"lightbox[groupe]\"" : "") + " href=\"" + url + "\" >[" + extension[0] + "]</a>"
334 }
335 return M.replace(this.regexUrl, traitementUrl)
336 }
337
338 /**
339 * Renvoie une version courte de l'url.
340 * par exemple : http://en.wikipedia.org/wiki/Yakov_Smirnoff devient wikipedia.org
341 */
342 Formateur.prototype.getShort = function(url)
343 {
344 var estUneImage = false
345 var versionShort = null
346 var rechercheImg = this.regexImg.exec(url)
347 //alert(url)
348 if (rechercheImg != null)
349 {
350 versionShort = rechercheImg[1].toLowerCase()
351 if (versionShort == "jpeg") versionShort = "jpg" // jpeg -> jpg
352 estUneImage = true
353 }
354 else
355 {
356 var rechercheDomaine = this.regexDomaine.exec(url)
357 if (rechercheDomaine != null && rechercheDomaine.length >= 2)
358 versionShort = rechercheDomaine[1]
359 else
360 {
361 var nomProtocole = this.regexNomProtocole.exec(url)
362 if (nomProtocole != null && nomProtocole.length >= 2)
363 versionShort = nomProtocole[1]
364 }
365 }
366
367 return [versionShort == null ? "url" : versionShort, estUneImage]
368 }
369
370 /**
371 * Traite les pseudo et messages à être affiché dans le titre d'une image visualisé avec lightbox.
372 */
373 Formateur.prototype.traiterPourFenetreLightBox = function(M, urlCourante)
374 {
375 thisFormateur = this
376 var traitementUrl = function(url)
377 {
378 return "[" + thisFormateur.getShort(url)[0] + (urlCourante == url ? ": image courante" : "") + "]"
379 }
380
381 return this.remplacerBalisesHTML(M).replace(this.regexUrl, traitementUrl)
382 }
383
384
385 ///////////////////////////////////////////////////////////////////////////////////////////////////
386
387 var statutType = {enregistre: 0, identifie: 1, non_identifie: 2}
388
389 function Client(util)
390 {
391 this.util = util
392
393 this.cookie = null
394 this.regexCookie = new RegExp("^cookie=([^;]*)")
395
396 // Obsolète
397 //this.captchaCrypt = null
398
399 // données personnels
400 this.resetDonneesPersonnelles()
401
402 this.setStatut(statutType.non_identifie)
403
404 // le dernier message d'erreur recut du serveur (par exemple une connexion foireuse : "login impossible")
405 this.dernierMessageErreur = ""
406 }
407
408 Client.prototype.resetDonneesPersonnelles = function()
409 {
410 this.pseudo = conf.pseudoDefaut
411 this.login = ""
412 this.password = ""
413 this.email = ""
414 this.css = jQuery("link#cssPrincipale").attr("href")
415
416 // les conversations, une conversation est un objet possédant les attributs suivants :
417 // - racine (entier)
418 // - page (entier)
419 this.conversations = new Array()
420 }
421
422 Client.prototype.setCss = function(css)
423 {
424 if (this.css == css)
425 return
426
427 this.css = css
428 jQuery("link#cssPrincipale").attr("href", this.css)
429 this.majMenu()
430
431 if (this.identifie())
432 this.flush()
433 }
434
435 /**
436 * Ajoute une conversation à la vue de l'utilisateur.
437 * Le profile de l'utilisateur est directement sauvegardé sur le serveur.
438 * @param racines la racine de la conversation
439 */
440 Client.prototype.ajouterConversation = function(racine)
441 {
442 this.conversations.push({racine : racine, page : 1})
443 this.flush()
444 }
445
446 Client.prototype.getXMLlogin = function(login, password)
447 {
448 var XMLDocument = this.util.creerDocumentXMLAction()
449 XMLDocument.documentElement.setAttribute("name", "login")
450
451 var nodeLogin = XMLDocument.createElement("login")
452 nodeLogin.appendChild(XMLDocument.createTextNode(login))
453 XMLDocument.documentElement.appendChild(nodeLogin)
454
455 var nodePassword = XMLDocument.createElement("password")
456 nodePassword.appendChild(XMLDocument.createTextNode(password))
457 XMLDocument.documentElement.appendChild(nodePassword)
458
459 return XMLDocument
460 }
461
462 Client.prototype.getXMLloginCookie = function()
463 {
464 var XMLDocument = this.util.creerDocumentXMLAction()
465 XMLDocument.documentElement.setAttribute("name", "login")
466
467 var nodeCookie = XMLDocument.createElement("cookie")
468 nodeCookie.appendChild(XMLDocument.createTextNode(this.cookie))
469 XMLDocument.documentElement.appendChild(nodeCookie)
470
471 return XMLDocument
472 }
473
474 /* Obsolète
475 Client.prototype.getXMLloginCaptcha = function(captchaCrypt, captchaInput)
476 {
477 var XMLDocument = this.util.creerDocumentXMLAction()
478 XMLDocument.documentElement.setAttribute("name", "loginCaptcha")
479
480 var nodecaptchaCrypt = XMLDocument.createElement("captchaCrypt")
481 nodecaptchaCrypt.appendChild(XMLDocument.createTextNode(captchaCrypt))
482 XMLDocument.documentElement.appendChild(nodecaptchaCrypt)
483
484 var nodecaptchaInput = XMLDocument.createElement("captchaInput")
485 nodecaptchaInput.appendChild(XMLDocument.createTextNode(captchaInput))
486 XMLDocument.documentElement.appendChild(nodecaptchaInput)
487
488 return XMLDocument
489 }*/
490
491 /* Obsolète
492 Client.prototype.getXMLgenerationCaptcha = function()
493 {
494 var XMLDocument = this.util.creerDocumentXMLAction()
495 XMLDocument.documentElement.setAttribute("name", "generationCaptcha")
496
497 return XMLDocument
498 }*/
499
500 Client.prototype.getXMLEnregistrement = function(login, password)
501 {
502 var XMLDocument = this.util.creerDocumentXMLAction()
503 XMLDocument.documentElement.setAttribute("name", "register")
504
505 var nodeLogin = XMLDocument.createElement("login")
506 nodeLogin.appendChild(XMLDocument.createTextNode(login))
507 XMLDocument.documentElement.appendChild(nodeLogin)
508
509 var nodePassword = XMLDocument.createElement("password")
510 nodePassword.appendChild(XMLDocument.createTextNode(password))
511 XMLDocument.documentElement.appendChild(nodePassword)
512
513 return XMLDocument
514 }
515
516 Client.prototype.getXMLProfile = function()
517 {
518 var XMLDocument = this.util.creerDocumentXMLAction()
519 XMLDocument.documentElement.setAttribute("name", "profile")
520
521 var nodeCookie = XMLDocument.createElement("cookie")
522 nodeCookie.appendChild(XMLDocument.createTextNode(this.cookie))
523 XMLDocument.documentElement.appendChild(nodeCookie)
524
525 var nodeLogin = XMLDocument.createElement("login")
526 nodeLogin.appendChild(XMLDocument.createTextNode(this.login))
527 XMLDocument.documentElement.appendChild(nodeLogin)
528
529 var nodePassword = XMLDocument.createElement("password")
530 nodePassword.appendChild(XMLDocument.createTextNode(this.password))
531 XMLDocument.documentElement.appendChild(nodePassword)
532
533 var nodePseudo = XMLDocument.createElement("pseudo")
534 nodePseudo.appendChild(XMLDocument.createTextNode(this.pseudo))
535 XMLDocument.documentElement.appendChild(nodePseudo)
536
537 var nodeEmail = XMLDocument.createElement("email")
538 nodeEmail.appendChild(XMLDocument.createTextNode(this.email))
539 XMLDocument.documentElement.appendChild(nodeEmail)
540
541 var nodeCSS = XMLDocument.createElement("css")
542 nodeCSS.appendChild(XMLDocument.createTextNode(this.css))
543 XMLDocument.documentElement.appendChild(nodeCSS)
544
545 // mémorise les conversations affichées
546 if (this.conversations.length > 0)
547 {
548 var nodeConversations = XMLDocument.createElement("conversations")
549 XMLDocument.documentElement.appendChild(nodeConversations)
550 for (var i = 0; i < this.conversations.length; i++)
551 {
552 var nodeConv = XMLDocument.createElement("conversation")
553 nodeConversations.appendChild(nodeConv)
554
555 var nodeRacine = XMLDocument.createElement("racine")
556 nodeRacine.appendChild(XMLDocument.createTextNode(this.conversations[i].racine))
557 nodeConv.appendChild(nodeRacine)
558
559 var nodePage = XMLDocument.createElement("page")
560 nodePage.appendChild(XMLDocument.createTextNode(this.conversations[i].page))
561 nodeConv.appendChild(nodePage)
562 }
563 }
564
565 return XMLDocument
566 }
567
568 /**
569 * Renvoie null si pas définit.
570 */
571 Client.prototype.getCookie = function()
572 {
573 var cookie = this.regexCookie.exec(document.cookie)
574 if (cookie == null) this.cookie = null
575 else this.cookie = cookie[1]
576 }
577
578 Client.prototype.delCookie = function()
579 {
580 document.cookie = "cookie=; max-age=0"
581 }
582
583 Client.prototype.setCookie = function(cookie)
584 {
585 if (this.cookie == null)
586 return
587
588 document.cookie =
589 "cookie="+this.cookie+
590 "; max-age=" + (60 * 60 * 24 * 365)
591 }
592
593 Client.prototype.identifie = function()
594 {
595 return this.statut == statutType.enregistre || this.statut == statutType.identifie
596 }
597
598 Client.prototype.setStatut = function(statut)
599 {
600 if(typeof(statut) == "string")
601 {
602 statut =
603 statut == "enregistre" ?
604 statutType.enregistre : (statut == "identifie" ? statutType.identifie : statutType.non_identifie)
605 }
606
607 if (statut == this.statut) return
608
609 this.statut = statut
610 this.majMenu()
611 }
612
613 /**
614 * Demande la génération d'un captcha au serveur et l'affiche.
615 */
616 /* Obsolète
617 Client.prototype.afficherCaptcha = function(query)
618 {
619 var thisClient = this
620
621 $.post("request", this.util.xmlVersAction(this.getXMLgenerationCaptcha()),
622 function(data, textStatus)
623 {
624 var chemin = jQuery("chemin", data.documentElement).text()
625 thisClient.captchaCrypt = jQuery("captchaCrypt", data.documentElement).text()
626 jQuery(query).prepend(
627 "<p id=\"captcha\" >Es-tu un bot ? <img class=\"captchaImg\" src=\"" + chemin + "\" />" +
628 "<input name=\"captchaInput\" type=\"text\" size=\"5\" max_length=\"5\" ></p>"
629 )
630 }
631 )
632 }
633
634 Client.prototype.cacherCaptcha = function()
635 {
636 jQuery("#captcha").remove()
637 }*/
638
639 /**
640 * Effectue la connexion vers le serveur.
641 * Cette fonction est bloquante tant que la connexion n'a pas été établie.
642 * S'il existe un cookie en local on s'authentifie directement avec lui.
643 * Si il n'est pas possible de s'authentifier alors on affiche un captcha anti-bot.
644 */
645 Client.prototype.connexionCookie = function()
646 {
647 this.getCookie()
648 if (this.cookie == null) return false;
649 return this.connexion(this.util.xmlVersAction(this.getXMLloginCookie()))
650 }
651
652 Client.prototype.connexionLogin = function(login, password)
653 {
654 return this.connexion(this.util.xmlVersAction(this.getXMLlogin(login, password)))
655 }
656
657 /* Obsolète
658 Client.prototype.connexionCaptcha = function()
659 {
660 return this.connexion(this.util.xmlVersAction(this.getXMLloginCaptcha(this.captchaCrypt, jQuery("#captcha input").val())))
661 }*/
662
663 Client.prototype.enregistrement = function(login, password)
664 {
665 if (this.identifie())
666 {
667 this.login = login
668 this.password = password
669 if(this.flush())
670 this.setStatut(statutType.enregistre)
671 return true
672 }
673 else
674 {
675 if (login == undefined) login = ""
676 if (password == undefined) password = ""
677 return this.connexion(this.util.xmlVersAction(this.getXMLEnregistrement(login, password)))
678 }
679 }
680
681 Client.prototype.connexion = function(action)
682 {
683 thisClient = this
684 jQuery.ajax(
685 {
686 async: false,
687 type: "POST",
688 url: "request",
689 dataType: "xml",
690 data: action,
691 success:
692 function(data)
693 {
694 thisClient.chargerDonnees(data)
695 }
696 }
697 )
698 return this.identifie()
699 }
700
701 Client.prototype.deconnexion = function()
702 {
703 this.setStatut(statutType.non_identifie) // deconnexion
704 this.resetDonneesPersonnelles()
705 this.delCookie ()
706 }
707
708 Client.prototype.chargerDonnees = function(data)
709 {
710 this.setStatut(jQuery("statut", data.documentElement).text())
711
712 if (this.identifie())
713 {
714 this.cookie = jQuery("cookie", data.documentElement).text()
715 this.setCookie()
716
717 this.login = jQuery("login", data.documentElement).text()
718 this.pseudo = jQuery("pseudo", data.documentElement).text()
719 this.email = jQuery("email", data.documentElement).text()
720 this.css = jQuery("css", data.documentElement).text()
721 // met à jour la css
722 if (this.css != "")
723 {
724 jQuery("link#cssPrincipale").attr("href", this.css)
725 this.majMenu()
726 }
727 }
728 this.dernierMessageErreur = jQuery("information", data.documentElement).text()
729 }
730
731 /**
732 * Met à jour les données personne sur serveur.
733 */
734 Client.prototype.flush = function()
735 {
736 thisClient = this
737 //thisClient.util.log(this.util.xmlVersAction(this.getXMLProfile()).action)
738 jQuery.ajax(
739 {
740 async: true,
741 type: "POST",
742 url: "request",
743 dataType: "xml",
744 data: this.util.xmlVersAction(this.getXMLProfile()),
745 success:
746 function(data)
747 {
748 //thisClient.util.log(thisClient.util.serializer.serializeToString(data))
749 }
750 }
751 )
752 // TODO : retourner false si un problème est survenu lors de l'update du profile
753 return true
754 }
755
756 Client.prototype.majMenu = function()
757 {
758 var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client
759
760 // met à jour le menu
761 if (this.statut == statutType.enregistre)
762 {
763 jQuery("#menu .profile").css("display", displayType).text("profile")
764 jQuery("#menu .logout").css("display", displayType)
765 jQuery("#menu .register").css("display", "none")
766 }
767 else if (this.statut == statutType.identifie)
768 {
769 jQuery("#menu .profile").css("display", "none")
770 jQuery("#menu .logout").css("display", displayType)
771 jQuery("#menu .register").css("display", displayType)
772 }
773 else
774 {
775 jQuery("#menu .profile").css("display", displayType).text("login")
776 jQuery("#menu .logout").css("display", "none")
777 jQuery("#menu .register").css("display", displayType)
778 }
779 }
780
781 ///////////////////////////////////////////////////////////////////////////////////////////////////
782
783 jQuery.noConflict()
784
785
786 // le main
787 jQuery(document).ready(
788 function()
789 {
790 /* FIXME : ce code pose problème sur konqueror, voir : http://www.kde-forum.org/thread.php?threadid=17993
791 var p = new DOMParser();
792 var doc = p.parseFromString("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<action/>", "text/xml")
793 var s = new XMLSerializer()
794 alert(s.serializeToString(doc)) */
795
796 var util = new Util()
797 var client = new Client(util)
798 var pages = new Pages()
799 var formateur = new Formateur()
800
801 // connexion vers le serveur (utilise un cookie qui traine)
802 client.connexionCookie()
803
804 // les styles css
805 for (var i = 1; i <= 3; i++)
806 {
807 jQuery("#css"+i).click(function(){
808 client.setCss("css/" + jQuery(this).attr("id").charAt(3) + "/euphorik.css")
809 })
810 }
811
812 jQuery("#menu .minichat").click(function(){ pages.afficherPage("minichat") })
813 jQuery("#menu .profile").click(function(){ pages.afficherPage("profile") })
814 jQuery("#menu .logout").click(function(){
815 util.messageDialogue("Êtes-vous sur de vouloir vous délogger ?", messageType.question,
816 {"Oui" : function()
817 {
818 client.deconnexion();
819 pages.afficherPage("minichat", true)
820 },
821 "Non" : function(){}
822 }
823 )
824 })
825 jQuery("#menu .register").click(function(){ pages.afficherPage("register") })
826
827 pages.ajouterPage(new PageMinichat(client, formateur, util))
828 pages.ajouterPage(new PageProfile(client, formateur, util))
829 pages.ajouterPage(new PageRegister(client, formateur, util))
830 pages.afficherPage("minichat")
831 }
832 )
833