ADD avancement sur la possibilité de réduire une conversation (pas fini)
[euphorik.git] / js / pageProfile.js
1 // coding: utf-8
2 // Copyright 2008 Grégory Burri
3 //
4 // This file is part of Euphorik.
5 //
6 // Euphorik is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // Euphorik is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
18
19 function PageProfile(client, formateur, util)
20 {
21 this.nom = "profile"
22
23 this.client = client
24 this.formateur = formateur
25 this.util = util
26 }
27
28 PageProfile.prototype.contenu = function()
29 {
30 // pourquoi ?
31 return ""
32 }
33
34 PageProfile.prototype.charger = function()
35 {
36 $("#page").html(this.getHTML())
37
38 // en fonction du statut
39 if (this.client.authentifie())
40 this.chargerProfile()
41 else
42 this.chargerLogin()
43
44 $("#page form#profile").submit(function(){return false})
45 }
46
47 PageProfile.prototype.chargerProfile = function()
48 {
49 var thisPage = this
50
51 $("form#profile input.login").val(this.client.login)
52 $("form#profile input.pseudo").val(this.client.pseudo)
53 $("form#profile input.email").val(this.client.email)
54 $("form#profile input#viewTooltips").attr("checked", this.client.viewTooltips)
55 $("form#profile input#viewTimes").attr("checked", this.client.viewTimes)
56
57 $("form#profile select#degreeOstentatoire option").removeAttr("selected")
58 $("form#profile select#degreeOstentatoire option[value=" + this.client.ostentatiousMaster + "]").attr("selected", "selected")
59
60 $("form#profile select#affichagePseudo option").removeAttr("selected")
61 $("form#profile select#affichagePseudo option[value=" + this.client.nickFormat + "]").attr("selected", "selected")
62
63 $("form#profile button").click(
64 function()
65 {
66 thisPage.client.pseudo = thisPage.formateur.filtrerInputPseudo($("form#profile input.pseudo").val())
67 thisPage.client.email = $("form#profile input.email").val()
68 thisPage.client.nickFormat = $("form#profile select#affichagePseudo option:selected").attr("value")
69 thisPage.client.ostentatiousMaster = $("form#profile select#degreeOstentatoire option:selected").attr("value")
70 thisPage.client.viewTooltips = $("form#profile input#viewTooltips").attr("checked")
71 thisPage.client.viewTimes = $("form#profile input#viewTimes").attr("checked")
72
73 var password = $("form#profile input.password").val()
74 var passwordRe = $("form#profile input.passwordRe").val()
75 if (password != "" || passwordRe != "")
76 {
77 if (password != passwordRe)
78 {
79 thisPage.util.messageDialogue("Les mots de passes ne correspondent pas")
80 return
81 }
82 thisPage.client.password = thisPage.util.md5(password)
83 }
84
85 if(!thisPage.client.flush())
86 thisPage.util.messageDialogue("Impossible de mettre à jour votre profile, causes inconnues", messageType.erreur)
87 else
88 {
89 thisPage.util.messageDialogue("Votre profile a été mis à jour")
90 thisPage.pages.afficherPage("minichat")
91 }
92 }
93 )
94 }
95
96 PageProfile.prototype.chargerLogin = function()
97 {
98 var thisPage = this
99
100 $("#page form#profile button").click(
101 function()
102 {
103 if(thisPage.client.connexionLogin($("form#profile input.login").val(), thisPage.util.md5($("form#profile input.password").val())))
104 {
105 // TODO afficher un message "ok"
106 thisPage.pages.afficherPage("minichat")
107 }
108 }
109 )
110 }
111
112 PageProfile.prototype.getHTML = function()
113 {
114 return '\
115 <form action="" id="profile" >\
116 <table>\
117 <tr>\
118 <td>login</td>\
119 <td><input class="login" type="text" size="20" maxlength="20" ' + (this.client.authentifie() ? 'readonly="readonly"' : '') + ' /></td>\
120 </tr>\
121 <tr>\
122 <td>password</td>\
123 <td><input class="password" type="password" size="20" maxlength="20"/></td>\
124 </tr>' +
125 (this.client.authentifie() ? '\
126 <tr>\
127 <td>password re</td>\
128 <td><input class="passwordRe" type="password" size="20" maxlength="20"/></td>\
129 </tr>\
130 <tr>\
131 <td>pseudo</td>\
132 <td><input class="pseudo" type="text" size="40" maxlength="20"/></td>\
133 </tr>\
134 <tr>\
135 <td>e-mail</td>\
136 <td><input class="email" type="text" size="40" maxlength="100"/></td>\
137 </tr>\
138 <tr>' +
139 (this.client.ekMaster ? '<td>Degrée d\'ostentation</td>\
140 <td>\
141 <select id="degreeOstentatoire">\
142 <option value="invisible">Aucun</option>\
143 <option value="light">Léger</option>\
144 <option value="heavy">Lourd</option>\
145 </select>\
146 </td>' : '') +
147 '</tr>\
148 <tr>\
149 <td>Affichage des identifiants</td>\
150 <td>\
151 <select id="affichagePseudo">\
152 <option value="nick">Pseudo</option>\
153 <option value="login">Login</option>\
154 <option value="nick_login">Pseudo(Login)</option>\
155 </select>\
156 </td>\
157 </tr>\
158 <tr>\
159 <td>Afficher les infos bulles</td>\
160 <td><input type="checkbox" id="viewTooltips" /></td>\
161 </tr>\
162 <tr>\
163 <td>Afficher les dates</td>\
164 <td><input type="checkbox" id="viewTimes" /></td>\
165 </tr>' : '') + '\
166 <tr>\
167 <td></td>\
168 <td><button>Valider</button>\
169 </tr>\
170 </table>\
171 </form>'
172 }
173