X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fclient.js;h=0b77e651306cf45a225f0f860f02a1b68b1e5afa;hp=c378075daa34e2439244d1d41cc1efcd3a51bcaa;hb=cf274dbe8b2049cfb3d2116d9298bfb8c1a38d11;hpb=8ee1535f5594573931ddaebee77bf6148a5358cb diff --git a/js/client.js b/js/client.js index c378075..0b77e65 100644 --- a/js/client.js +++ b/js/client.js @@ -19,7 +19,18 @@ /*jslint laxbreak:true */ /** - * Représente l'utilisateur du site. + * Object that represents the user. + * It carries all the user data like + * - ID + * - Nick + * - E-Mail + * - etc.. + * It can access directly to the DOM if needed. Some examples : + * - Changes the menu if the user is logged or not + * - Changes the logo if the user is an ek master + * - etc.. + * @util See util.js. + * @communication See communication.js. */ euphorik.Client = function(util, communication) { this.util = util; @@ -28,72 +39,91 @@ euphorik.Client = function(util, communication) { this.cookie = null; this.regexCookie = /cookie=([^;]*)/; - // données personnels - this.resetDonneesPersonnelles(); + this.resetPersonalData(); - this.setStatut(euphorik.Client.statutType.deconnected); + this.setStatus(euphorik.Client.statusType.disconnected); - // si true alors chaque modification du client est mémorisé sur le serveur + // If true then each data change is flushed to the server. + // Active only for opera which doesn't support the unload event. this.autoflush = $.browser.opera; }; -// les statuts possibes du client -euphorik.Client.statutType = { - // mode enregistré, peut poster des messages et modifier son profile +// The three status of a client. +euphorik.Client.statusType = { + // authentified and registered : The user can post messages and can modify his profile auth_registered : 0, - // mode identifié, peut poster des messages mais n'a pas accès au profile + // authentified but not registered : The user can only post messages auth_not_registered : 1, - // mode déconnecté, ne peut pas poster de message - deconnected : 2 + // disconnected (the initial state) : The user cannot post message + disconnected : 2 }; -euphorik.Client.prototype.resetDonneesPersonnelles = function() { +/** + * Reset all the local personal data. Does not erase the remote data. + * This function is used during disconnecting. + */ +euphorik.Client.prototype.resetPersonalData = function() { this.id = 0; - this.pseudo = euphorik.conf.pseudoDefaut; + this.nick = euphorik.conf.defaultNick; this.login = ""; this.password = ""; this.email = ""; - this.css = $("link#cssPrincipale").attr("href"); + this.css = $("link#mainCss").attr("href"); this.chatOrder = "reverse"; this.nickFormat = "nick"; this.viewTimes = true; this.viewTooltips = true; this.cookie = undefined; - this.pagePrincipale = 1; + this.mainConversationPage = 1; this.ekMaster = false; this.ostentatiousMaster = "light"; - - // les conversations, une conversation est un objet possédant les propriétés suivantes : - // - root (entier) - // - page (entier) - // - reduit (bool) + + // The user opened conversations. + // Each conversation object owns theses properties : + // - root (integer) + // - page (integer) + // - isCollapsed (bool) this.conversations = []; }; +/** + * Set the CSS. Dynamically change the href to the CSS in the DOM. + * @css The relative path to the CSS file, for example : + * "styles/1/euphorik.css". + */ euphorik.Client.prototype.setCss = function(css) { if (this.css === css || !css) { return; } this.css = css; - $("link#cssPrincipale").attr("href", this.css); + $("link#mainCss").attr("href", this.css); + if (this.autoflush) { this.flush(true); } }; -euphorik.Client.prototype.pageSuivante = function(numConv) { - if (numConv < 0 && this.pagePrincipale > 1) { - this.pagePrincipale -= 1; +/** + * Change the current page to the next one for the given conversation. + * @numConv The number of the conversation. + */ +euphorik.Client.prototype.nextPage = function(numConv) { + if (numConv < 0 && this.mainConversationPage > 1) { + this.mainConversationPage -= 1; } else if (this.conversations[numConv].page > 1) { this.conversations[numConv].page -= 1; } }; -euphorik.Client.prototype.pagePrecedente = function(numConv) { +/** + * Change the current page to the previous one for the given conversation. + * @numConv The number of the conversation. + */ +euphorik.Client.prototype.previousPage = function(numConv) { if (numConv < 0) { - this.pagePrincipale += 1; + this.mainConversationPage += 1; } else { this.conversations[numConv].page += 1; } @@ -103,13 +133,13 @@ euphorik.Client.prototype.pagePrecedente = function(numConv) { * Définit la première page pour la conversation donnée. * @return true si la page a changé sinon false */ -euphorik.Client.prototype.goPremierePage = function(numConv) +euphorik.Client.prototype.goFirstPage = function(numConv) { if (numConv < 0) { - if (this.pagePrincipale === 1) { + if (this.mainConversationPage === 1) { return false; } - this.pagePrincipale = 1; + this.mainConversationPage = 1; } else { if (this.conversations[numConv].page === 1) { return false; @@ -137,7 +167,7 @@ euphorik.Client.prototype.ajouterConversation = function(racine) { return false; } - this.conversations.push({root : racine, page : 1, reduit : false}); + this.conversations.push({root : racine, page : 1, isCollapsed : false}); if (this.autoflush) { this.flush(true); } @@ -164,7 +194,7 @@ euphorik.Client.prototype.supprimerConversation = function(num) { euphorik.Client.prototype.getJSONConversations = function() { var conversations = []; this.conversations.each(function(i, conv) { - conversations.push({ "root" : conv.root, "minimized" : conv.reduit }); + conversations.push({ "root" : conv.root, "minimized" : conv.isCollapsed }); }); return conversations; }; @@ -180,7 +210,7 @@ euphorik.Client.prototype.getJSONProfile = function() { euphorik.Client.prototype.getJSONProfileInfos = function() { return { - "nick" : this.pseudo, + "nick" : this.nick, "email" : this.email, "css" : this.css, "chat_order" : this.chatOrder, @@ -214,7 +244,7 @@ euphorik.Client.prototype.setCookie = function() { return; } - // ne fonctionne pas sous IE.... + // doesn't work under IE.... /*document.cookie = "cookie=" + this.cookie + "; max-age=" + (60 * 60 * 24 * 365) */ document.cookie = @@ -222,17 +252,17 @@ euphorik.Client.prototype.setCookie = function() { }; euphorik.Client.prototype.authentifie = function() { - return this.statut === euphorik.Client.statutType.auth_registered || this.statut === euphorik.Client.statutType.auth_not_registered; + return this.statut === euphorik.Client.statusType.auth_registered || this.statut === euphorik.Client.statusType.auth_not_registered; }; -euphorik.Client.prototype.setStatut = function(statut) +euphorik.Client.prototype.setStatus = function(statut) { // conversation en "enum" si en "string" if (typeof(statut) === "string") { statut = statut === "auth_registered" ? - euphorik.Client.statutType.auth_registered : - (statut === "auth_not_registered" ? euphorik.Client.statutType.auth_not_registered : euphorik.Client.statutType.deconnected); + euphorik.Client.statusType.auth_registered : + (statut === "auth_not_registered" ? euphorik.Client.statusType.auth_not_registered : euphorik.Client.statusType.disconnected); } if (statut === this.statut) { @@ -244,14 +274,12 @@ euphorik.Client.prototype.setStatut = function(statut) this.majMenu(); this.majLogo(); }; - -/** - * Effectue la connexion vers le serveur. - * Cette fonction est bloquante tant que la connexion n'a pas été établie. - * S'il existe un cookie en local on s'authentifie directement avec lui. - * Si il n'est pas possible de s'authentifier alors on affiche un captcha anti-bot. + +/** + * Try to authentify the client with the cookie information. + * Do nothing if there is no cookie. */ -euphorik.Client.prototype.connexionCookie = function() { +euphorik.Client.prototype.connectionCookie = function() { this.getCookie(); if (!this.cookie) { return false; @@ -268,7 +296,7 @@ euphorik.Client.prototype.enregistrement = function(login, password) { this.login = login; this.password = password; if(this.flush()) { - this.setStatut(euphorik.Client.statutType.auth_registered); + this.setStatus(euphorik.Client.statusType.auth_registered); return true; } return false; @@ -307,7 +335,7 @@ euphorik.Client.prototype.connexion = function(action, messageJson) { thisClient.chargerDonnees(data); }, function(data) { - thisClient.util.messageDialogue(data.error_message); + thisClient.util.messageDialog(data.error_message); thisClient.delCookie(); // suppression du cookie actuel, cas où le cookie du client ne permet pas une authentification }, false @@ -315,11 +343,11 @@ euphorik.Client.prototype.connexion = function(action, messageJson) { return this.authentifie(); }; -euphorik.Client.prototype.deconnexion = function() { +euphorik.Client.prototype.disconnect = function() { this.flush(true); this.delCookie(); - this.resetDonneesPersonnelles(); - this.setStatut(euphorik.Client.statutType.deconnected); // deconnexion + this.resetPersonalData(); + this.setStatus(euphorik.Client.statusType.disconnected); }; euphorik.Client.prototype.chargerDonnees = function(data) { @@ -327,7 +355,7 @@ euphorik.Client.prototype.chargerDonnees = function(data) { // de l'état ekMaster this.ekMaster = data.ek_master ? data.ek_master : false; - this.setStatut(data.status); + this.setStatus(data.status); if (this.authentifie()) { this.cookie = data.cookie; @@ -335,7 +363,7 @@ euphorik.Client.prototype.chargerDonnees = function(data) { this.id = data.id; this.login = data.login; - this.pseudo = data.profile.nick; + this.nick = data.profile.nick; this.email = data.profile.email; this.setCss(data.profile.css); this.chatOrder = data.profile.chat_order; @@ -345,12 +373,12 @@ euphorik.Client.prototype.chargerDonnees = function(data) { this.ostentatiousMaster = data.profile.ostentatious_master; // la page de la conversation principale - this.pagePrincipale = 1; + this.mainConversationPage = 1; // les conversations this.conversations = data.profile.conversations; this.conversations.map(function(conv) { - return { root : conv.root, page : 1, reduit : conv.minimized }; + return { root : conv.root, page : 1, isCollapsed : conv.minimized }; }); this.majBulle(); @@ -380,7 +408,7 @@ euphorik.Client.prototype.flush = function(async) { thisClient.majBulle(); }, function(data) { - thisClient.util.messageDialogue(data.error_message); + thisClient.util.messageDialog(data.error_message); ok = false; }, async @@ -395,11 +423,11 @@ euphorik.Client.prototype.majMenu = function() { $("#menu .admin").css("display", this.ekMaster ? displayType : "none"); // met à jour le menu - if (this.statut === euphorik.Client.statutType.auth_registered) { + if (this.statut === euphorik.Client.statusType.auth_registered) { $("#menu .profile").css("display", displayType).text("profile"); $("#menu .logout").css("display", displayType); $("#menu .register").css("display", "none"); - } else if (this.statut === euphorik.Client.statutType.auth_not_registered) { + } else if (this.statut === euphorik.Client.statusType.auth_not_registered) { $("#menu .profile").css("display", "none"); $("#menu .logout").css("display", displayType); $("#menu .register").css("display", displayType);