REPORT de la branche 1.1
[euphorik.git] / js / euphorik.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 /*jslint laxbreak:true */
20
21 // tout euphorik est contenu dans cet objet
22 var euphorik = {};
23
24 // le main
25 $(document).ready(
26 function() {
27 var fragment = new Fragment();
28 var formateur = new euphorik.Formateur();
29 var util = new euphorik.Util(formateur);
30 var communication = new euphorik.Communication(
31 function(data) { util.messageDialogue(data.error_message); },
32 function() { util.showWaitBar(); },
33 function() { util.hideWaitBar(); }
34 );
35 var client = new euphorik.Client(util, communication);
36 var pages = new euphorik.Pages(fragment, communication);
37
38 // connexion vers le serveur (utilise un cookie qui traine)
39 client.connexionCookie();
40
41 $("#menuCss").change(function() { client.setCss("styles/" + $("option:selected", this).attr("value") + "/euphorik.css"); });
42
43 // FIXME : ne fonctionne pas sous opera
44 // voir : http://dev.jquery.com/ticket/2892#preview
45 $(window).unload(function() { client.flush(); });
46
47 $("#menu .minichat").click(function() { pages.afficherPage("minichat"); });
48 $("#menu .admin").click(function() { pages.afficherPage("admin"); });
49 $("#menu .profile").click(function() { pages.afficherPage("profile"); });
50 $("#menu .logout").click(function() {
51 util.messageDialogue("Êtes-vous sur de vouloir vous délogger ?", euphorik.Util.messageType.question,
52 {
53 "Oui" : function() {
54 client.deconnexion();
55 pages.afficherPage("minichat", true);
56 },
57 "Non" : function() {}
58 }
59 );
60 });
61 $("#menu .register").click(function(){ pages.afficherPage("register"); });
62 $("#menu .about").click(function(){ pages.afficherPage("about"); });
63
64 // TODO : simplifier et pouvoir créer des liens par exemple : <span class="lien" href="conditions">Conditions d'utilisation</span>
65 $("#footer .conditions").click(function(){ pages.afficherPage("conditions_utilisation"); });
66
67 pages.ajouterPage(new euphorik.PageMinichat(client, formateur, util, communication), true);
68 pages.ajouterPage(new euphorik.PageAdmin(client, formateur, util, communication));
69 pages.ajouterPage(new euphorik.PageProfile(client, formateur, util));
70 pages.ajouterPage(new euphorik.PageRegister(client, formateur, util));
71 pages.ajouterPage(new euphorik.PageAbout(client, formateur, util, communication));
72 pages.ajouterPage("conditions_utilisation");
73
74 pages.afficherPage();
75 }
76 );