Cleaning...
[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 // all euphorik is contained in this object
22 var euphorik = {};
23
24 // le main
25 $(document).ready(
26 function() {
27 var fragment = new Fragment();
28 var formater = new euphorik.Formater();
29 var util = new euphorik.Util(formater);
30 var communication = new euphorik.Communication(
31 function(data) { util.messageDialog(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 // Client authentification with the cookie information (if it exists).
39 client.connectionCookie();
40
41 $("#menuCss").change(function() { client.setCss("styles/" + $("option:selected", this).attr("value") + "/euphorik.css"); });
42
43 $(window).unload(function() { client.flush(); });
44
45 $("#menu .minichat").click(function() { pages.displayPage("minichat"); });
46 $("#menu .admin").click(function() { pages.displayPage("admin"); });
47 $("#menu .profile").click(function() { pages.displayPage("profile"); });
48 $("#menu .logout").click(function() {
49 util.messageDialog("Are you sure you want to log out?", euphorik.Util.messageType.question,
50 {
51 "Yes" : function() {
52 client.disconnect();
53 pages.displayPage("minichat", true);
54 },
55 "No" : function() {}
56 }
57 );
58 });
59 $("#menu .register").click(function(){ pages.displayPage("register"); });
60 $("#menu .about").click(function(){ pages.displayPage("about"); });
61
62 // TODO: simplification : such link[1] should be created and automatically open the right page without
63 // explicitly add a page.
64 // [1] : <a class="pageLink" href="termes_of_use">Terms of use</a>
65 $("#footer .termsOfUse").click(function(){ pages.displayPage("terms_of_use"); });
66
67 pages.addPage(new euphorik.PageMinichat(client, formater, util, communication), true);
68 pages.addPage(new euphorik.PageAdmin(client, formater, util, communication));
69 pages.addPage(new euphorik.PageProfile(client, formater, util));
70 pages.addPage(new euphorik.PageRegister(client, formater, util));
71 pages.addPage(new euphorik.PageAbout(client, formater, util, communication));
72 pages.addPage("terms_of_use");
73
74 pages.displayPage(); // display the default page
75 }
76 );