MOD conception devient doc
[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 return ""
15 }
16
17 PageProfile.prototype.charger = function()
18 {
19 jQuery("#page").html(this.getHTML())
20
21 // en fonction du statut
22 if (this.client.identifie())
23 this.chargerProfile()
24 else
25 this.chargerLogin()
26
27 jQuery("#page form#profile").submit(function(){return false})
28 }
29
30 PageProfile.prototype.chargerProfile = function()
31 {
32 var thisPage = this
33
34 jQuery("form#profile input.login").val(this.client.login)
35 jQuery("form#profile input.pseudo").val(this.client.pseudo)
36 jQuery("form#profile input.email").val(this.client.email)
37
38 jQuery("#page form#profile button").click(
39 function()
40 {
41 thisPage.client.pseudo = thisPage.formateur.filtrerInputPseudo(jQuery("form#profile input.pseudo").val())
42 thisPage.client.email = jQuery("form#profile input.email").val()
43
44 var password = jQuery("form#profile input.password").val()
45 var passwordRe = jQuery("form#profile input.passwordRe").val()
46 if (password != "" || passwordRe != "")
47 {
48 if (password != passwordRe)
49 {
50 thisPage.util.messageDialogue("Les mots de passes ne correspondent pas")
51 return
52 }
53 thisPage.client.password = thisPage.util.md5(password)
54 }
55
56 if(!thisPage.client.flush())
57 thisPage.util.messageDialogue("Impossible de mettre à jour votre profile, causes inconnues", messageType.erreur)
58 else
59 {
60 thisPage.util.messageDialogue("Votre profile a été mis à jour")
61 //thisPage.pages.afficherPage("minichat")
62 }
63 }
64 )
65 }
66
67 PageProfile.prototype.chargerLogin = function()
68 {
69 var thisPage = this
70
71 jQuery("#page form#profile button").click(
72 function()
73 {
74 if(!thisPage.client.connexionLogin(jQuery("form#profile input.login").val(), thisPage.util.md5(jQuery("form#profile input.password").val())))
75 thisPage.util.messageDialogue("Couple login/pass introuvable")
76 else
77 {
78 // TODO afficher un message "ok"
79 thisPage.pages.afficherPage("minichat")
80 }
81 }
82 )
83 }
84
85 PageProfile.prototype.getHTML = function()
86 {
87 return '\
88 <form id="profile" >\
89 <table>\
90 <tr>\
91 <td>login</td>\
92 <td><input class="login" type="text" size="20" maxlength="20" ' + (this.client.identifie() ? 'readonly="readonly"' : '') + ' /></td>\
93 </tr>\
94 <tr>\
95 <td>password</td>\
96 <td><input class="password" type="password" size="20" maxlength="20"/></td>\
97 </tr>' +
98 (this.client.identifie() ? '\
99 <tr>\
100 <td>password re</td>\
101 <td><input class="passwordRe" type="password" size="20" maxlength="20"/></td>\
102 </tr>\
103 <tr>\
104 <td>pseudo</td>\
105 <td><input class="pseudo" type="text" size="40" maxlength="20"/></td>\
106 </tr>\
107 <tr>\
108 <td>e-mail</td>\
109 <td><input class="email" type="text" size="40" maxlength="100"/></td>\
110 </tr>\
111 <tr>' : '') + '\
112 <tr>\
113 <td></td>\
114 <td><button>Valider</button>\
115 </tr>\
116 </table>\
117 </form>'
118 }