(no commit message)
[euphorik.git] / js / pageProfile.js
1 // coding: utf-8
2
3 function PageProfile(client, formateur, util)
4 {
5 this.nom = "profile"
6
7 this.client = client
8 this.formateur = formateur
9 this.util = util
10 }
11
12 PageProfile.prototype.contenu = function()
13 {
14 // pourquoi ?
15 return ""
16 }
17
18 PageProfile.prototype.charger = function()
19 {
20 $("#page").html(this.getHTML())
21
22 // en fonction du statut
23 if (this.client.authentifie())
24 this.chargerProfile()
25 else
26 this.chargerLogin()
27
28 $("#page form#profile").submit(function(){return false})
29 }
30
31 PageProfile.prototype.chargerProfile = function()
32 {
33 var thisPage = this
34
35 $("form#profile input.login").val(this.client.login)
36 $("form#profile input.pseudo").val(this.client.pseudo)
37 $("form#profile input.email").val(this.client.email)
38
39 $("form#profile select#affichagePseudo option").removeAttr("selected")
40 $("form#profile select#affichagePseudo option[value=" + this.client.nickFormat + "]").attr("selected", "selected")
41
42
43 $("form#profile button").click(
44 function()
45 {
46 thisPage.client.pseudo = thisPage.formateur.filtrerInputPseudo($("form#profile input.pseudo").val())
47 thisPage.client.email = $("form#profile input.email").val()
48 thisPage.client.nickFormat = $("form#profile select#affichagePseudo option:selected").attr("value")
49
50 var password = $("form#profile input.password").val()
51 var passwordRe = $("form#profile input.passwordRe").val()
52 if (password != "" || passwordRe != "")
53 {
54 if (password != passwordRe)
55 {
56 thisPage.util.messageDialogue("Les mots de passes ne correspondent pas")
57 return
58 }
59 thisPage.client.password = thisPage.util.md5(password)
60 }
61
62 if(!thisPage.client.flush())
63 thisPage.util.messageDialogue("Impossible de mettre à jour votre profile, causes inconnues", messageType.erreur)
64 else
65 {
66 thisPage.util.messageDialogue("Votre profile a été mis à jour")
67 //thisPage.pages.afficherPage("minichat")
68 }
69 }
70 )
71 }
72
73 PageProfile.prototype.chargerLogin = function()
74 {
75 var thisPage = this
76
77 $("#page form#profile button").click(
78 function()
79 {
80 if(!thisPage.client.connexionLogin($("form#profile input.login").val(), thisPage.util.md5($("form#profile input.password").val())))
81 thisPage.util.messageDialogue("Couple login/pass introuvable")
82 else
83 {
84 // TODO afficher un message "ok"
85 thisPage.pages.afficherPage("minichat")
86 }
87 }
88 )
89 }
90
91 PageProfile.prototype.getHTML = function()
92 {
93 return '\
94 <form id="profile" >\
95 <table>\
96 <tr>\
97 <td>login</td>\
98 <td><input class="login" type="text" size="20" maxlength="20" ' + (this.client.authentifie() ? 'readonly="readonly"' : '') + ' /></td>\
99 </tr>\
100 <tr>\
101 <td>password</td>\
102 <td><input class="password" type="password" size="20" maxlength="20"/></td>\
103 </tr>' +
104 (this.client.authentifie() ? '\
105 <tr>\
106 <td>password re</td>\
107 <td><input class="passwordRe" type="password" size="20" maxlength="20"/></td>\
108 </tr>\
109 <tr>\
110 <td>pseudo</td>\
111 <td><input class="pseudo" type="text" size="40" maxlength="20"/></td>\
112 </tr>\
113 <tr>\
114 <td>e-mail</td>\
115 <td><input class="email" type="text" size="40" maxlength="100"/></td>\
116 </tr>\
117 <tr>\
118 <td>Affichage des identifiants</td>\
119 <td>\
120 <select id="affichagePseudo">\
121 <option value="nick">Pseudo</option>\
122 <option value="login">Login</option>\
123 <option value="nick_login">Pseudo(Login)</option>\
124 </select>\
125 </td>\
126 </tr>\
127 <tr>' : '') + '\
128 <tr>\
129 <td></td>\
130 <td><button>Valider</button>\
131 </tr>\
132 </table>\
133 </form>'
134 }
135