2ae3fb39d418cf2b940cb6cd3874c93f6ffae893
[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 euphorik.PageProfile = function(client, formater, util) {
20 this.nom = "profile";
21
22 this.client = client;
23 this.formater = formater;
24 this.util = util;
25 };
26
27 euphorik.PageProfile.prototype.contenu = function() {
28 // pourquoi ?
29 return "";
30 };
31
32 euphorik.PageProfile.prototype.charger = function() {
33 $("#page").html(this.getHTML());
34
35 // en fonction du statut
36 if (this.client.authentifie()) {
37 this.chargerProfile();
38 } else {
39 this.chargerLogin();
40 }
41
42 $("#page form#profile").submit(function(){ return false; });
43 };
44
45 euphorik.PageProfile.prototype.chargerProfile = function() {
46 var thisPage = this;
47
48 $("form#profile input.login").val(this.client.login);
49 $("form#profile input.nick").val(this.client.nick);
50 $("form#profile input.email").val(this.client.email);
51 $("form#profile input#viewTooltips").attr("checked", this.client.viewTooltips);
52 $("form#profile input#viewTimes").attr("checked", this.client.viewTimes);
53
54 $("form#profile select#chatOrder option").removeAttr("selected");
55 $("form#profile select#chatOrder option[value=" + this.client.chatOrder + "]").attr("selected", "selected");
56
57 $("form#profile select#affichagePseudo option").removeAttr("selected");
58 $("form#profile select#affichagePseudo option[value=" + this.client.nickFormat + "]").attr("selected", "selected");
59
60 if (this.client.ostentatiousMaster) {
61 $("form#profile select#degreeOstentatoire option").removeAttr("selected");
62 $("form#profile select#degreeOstentatoire option[value=" + this.client.ostentatiousMaster + "]").attr("selected", "selected");
63 }
64
65 $("form#profile button").click(
66 function() {
67 thisPage.client.nick = thisPage.formate.filtrerInputPseudo($("form#profile input.nick").val());
68 thisPage.client.email = $("form#profile input.email").val();
69 thisPage.client.chatOrder = $("form#profile select#chatOrder option:selected").attr("value");
70 thisPage.client.nickFormat = $("form#profile select#affichagePseudo option:selected").attr("value");
71 if (thisPage.client.ekMaster) {
72 thisPage.client.ostentatiousMaster = $("form#profile select#degreeOstentatoire option:selected").attr("value");
73 }
74 thisPage.client.viewTooltips = $("form#profile input#viewTooltips").attr("checked");
75 thisPage.client.viewTimes = $("form#profile input#viewTimes").attr("checked");
76
77 var password = $("form#profile input.password").val();
78 var passwordRe = $("form#profile input.passwordRe").val();
79 if (password !== "" || passwordRe !== "") {
80 if (password !== passwordRe) {
81 thisPage.util.messageDialog("Les mots de passes ne correspondent pas");
82 return;
83 }
84 thisPage.client.password = thisPage.util.md5(password);
85 }
86
87 if(!thisPage.client.flush()) {
88 thisPage.util.messageDialog("Impossible de mettre à jour votre profile, causes inconnues", euphorik.Util.messageType.erreur);
89 } else {
90 thisPage.util.messageDialog("Votre profile a été mis à jour");
91 thisPage.pages.displayPage("minichat");
92 }
93 }
94 );
95 };
96
97 euphorik.PageProfile.prototype.chargerLogin = function() {
98 var thisPage = this;
99
100 $("#page form#profile button").click(
101 function() {
102 if(thisPage.client.connexionLogin($("form#profile input.login").val(), thisPage.util.md5($("form#profile input.password").val()))) {
103 // TODO afficher un message "ok"
104 thisPage.pages.displayPage("minichat");
105 }
106 }
107 );
108 };
109
110 euphorik.PageProfile.prototype.getHTML = function() {
111 return '<form action="" id="profile" >' +
112 ' <table>' +
113 ' <tr>' +
114 ' <td>login</td>' +
115 ' <td><input class="login" type="text" size="20" maxlength="20" ' + (this.client.authentifie() ? 'readonly="readonly"' : '') + ' /></td>' +
116 (this.client.authentifie() ? '' : ' <td>(sensible à la <a href="http://fr.wikipedia.org/wiki/Casse_(informatique)">casse</a>)</td>') +
117 ' </tr>' +
118 ' <tr>' +
119 ' <td>password</td>' +
120 ' <td><input class="password" type="password" size="20" maxlength="20"/></td>' +
121 ' </tr>' +
122 (this.client.authentifie() ? '' +
123 ' <tr>' +
124 ' <td>password re</td>' +
125 ' <td><input class="passwordRe" type="password" size="20" maxlength="20"/></td>' +
126 ' </tr>' +
127 ' <tr>' +
128 ' <td>nick</td>' +
129 ' <td><input class="nick" type="text" size="40" maxlength="20"/></td>' +
130 ' </tr>' +
131 ' <tr>' +
132 ' <td>e-mail</td>' +
133 ' <td><input class="email" type="text" size="40" maxlength="100"/></td>' +
134 ' </tr>' +
135 ' <tr>' +
136 ' <td>Ordre des messages</td>' +
137 ' <td>' +
138 ' <select id="chatOrder">' +
139 ' <option value="chrono">Chronologique</option>' +
140 ' <option value="reverse">Anti-chronologique</option>' +
141 ' </select>' +
142 ' </td>' +
143 ' </tr>' +
144 ' <tr>' +
145 (this.client.ekMaster ? '' +
146 ' <td>Degrée d\'ostentation</td>' +
147 ' <td>' +
148 ' <select id="degreeOstentatoire">' +
149 ' <option value="invisible">Nul</option>' +
150 ' <option value="light">Faible</option>' +
151 ' <option value="heavy">Élevé</option>' +
152 ' </select>' +
153 ' </td>' : '') +
154 ' </tr>' +
155 ' <tr>' +
156 ' <td>Affichage des identifiants</td>' +
157 ' <td>' +
158 ' <select id="affichagePseudo">' +
159 ' <option value="nick">Pseudo</option>' +
160 ' <option value="login">Login</option>' +
161 ' <option value="nick_login">Pseudo(Login)</option>' +
162 ' </select>' +
163 ' </td>' +
164 ' </tr>' +
165 ' <tr>' +
166 ' <td>Afficher les infos bulles</td>' +
167 ' <td><input type="checkbox" id="viewTooltips" /></td>' +
168 ' </tr>' +
169 ' <tr>' +
170 ' <td>Afficher les dates</td>' +
171 ' <td><input type="checkbox" id="viewTimes" /></td>' +
172 ' </tr>' : '') +
173 ' <tr>' +
174 ' <td></td>' +
175 ' <td><button>Valider</button></td>' +
176 ' </tr>' +
177 ' </table>' +
178 '</form>';
179 };