X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fclient.js;h=1e872799ca8ab670f49da5d6aff9531f5f0db9ed;hp=5324f96063868653cead8239dc1cdd9fc0f19d2c;hb=5d9992368bb386d2e606ae037c5478fe10ac70e8;hpb=27c4a5ac9000ca933f28abfedbf9607f73619615 diff --git a/js/client.js b/js/client.js index 5324f96..1e87279 100644 --- a/js/client.js +++ b/js/client.js @@ -19,37 +19,52 @@ /*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; this.communication = communication; - + this.cookie = null; this.regexCookie = /cookie=([^;]*)/; - - // données personnels - this.resetDonneesPersonnelles(); - - this.setStatut(euphorik.Client.statutType.deconnected); - - // si true alors chaque modification du client est mémorisé sur le serveur + + this.resetPersonalData(); + + this.setStatus(euphorik.Client.statusType.disconnected); + + // 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 = ""; @@ -59,18 +74,24 @@ euphorik.Client.prototype.resetDonneesPersonnelles = function() { 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; @@ -78,22 +99,31 @@ euphorik.Client.prototype.setCss = function(css) { this.css = 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,12 @@ 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; @@ -126,7 +155,7 @@ euphorik.Client.prototype.goPremierePage = function(numConv) * @return true si la conversation a été créée sinon false (par exemple si la conv existe déjà) */ euphorik.Client.prototype.ajouterConversation = function(racine) { - // vérification s'il elle n'existe pas déjà + // vérification s'il elle n'existe pas déjà var existe = false; this.conversations.each(function(i, conv) { if (conv.root === racine) { @@ -136,12 +165,12 @@ euphorik.Client.prototype.ajouterConversation = function(racine) { if (existe) { 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); } - + return true; }; @@ -149,13 +178,13 @@ euphorik.Client.prototype.supprimerConversation = function(num) { if (num < 0 || num >= this.conversations.length) { return; } - - // décalage TODO : supprimer le dernier élément + + // décalage TODO : supprimer le dernier élément for (var i = num; i < this.conversations.length - 1; i++) { this.conversations[i] = this.conversations[i+1]; } this.conversations.pop(); - + if (this.autoflush) { this.flush(true); } @@ -164,7 +193,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 +209,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, @@ -213,45 +242,43 @@ euphorik.Client.prototype.setCookie = function() { if (!this.cookie) { return; } - - // ne fonctionne pas sous IE.... + + // doesn't work under IE.... /*document.cookie = "cookie=" + this.cookie + "; max-age=" + (60 * 60 * 24 * 365) */ - - document.cookie = + + document.cookie = "cookie="+this.cookie+"; expires=" + new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365).toUTCString(); }; 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) { return; } - + this.statut = 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; @@ -263,12 +290,12 @@ euphorik.Client.prototype.connexionLogin = function(login, password) { return this.connexion("authentification", {"login" : login, "password" : password }); }; -euphorik.Client.prototype.enregistrement = function(login, password) { +euphorik.Client.prototype.enregistrement = function(login, password) { if (this.authentifie()) { 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; @@ -283,14 +310,14 @@ euphorik.Client.prototype.enregistrement = function(login, password) { */ euphorik.Client.prototype.getJSONEnregistrement = function(login, password) { var mess = {}; - + if (login && password) { mess.login = login; mess.password = password; } - + mess.profile = this.getJSONProfileInfos(); - + return mess; }; @@ -299,7 +326,7 @@ euphorik.Client.prototype.getJSONEnregistrement = function(login, password) { */ euphorik.Client.prototype.connexion = function(action, messageJson) { var thisClient = this; - + this.communication.requete( action, messageJson, @@ -315,27 +342,27 @@ 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) { // la modification du statut qui suit met à jour le menu, le menu dépend (page admin) // 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; this.setCookie(); - + 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; @@ -343,16 +370,16 @@ euphorik.Client.prototype.chargerDonnees = function(data) { this.viewTimes = data.profile.view_times; this.viewTooltips = data.profile.view_tooltips; 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(); this.majCssSelectionee(); } @@ -365,19 +392,19 @@ euphorik.Client.prototype.chargerDonnees = function(data) { */ euphorik.Client.prototype.flush = function(async) { async = async || false; - + if (!this.authentifie()) { return false; } - + var thisClient = this; var ok = true; - + this.communication.requete( "set_profile", this.getJSONProfile(), function(data) { - thisClient.majBulle(); + thisClient.majBulle(); }, function(data) { thisClient.util.messageDialog(data.error_message); @@ -385,7 +412,7 @@ euphorik.Client.prototype.flush = function(async) { }, async ); - + return ok; }; @@ -393,13 +420,13 @@ euphorik.Client.prototype.majMenu = function() { var displayType = "block"; $("#menu .admin").css("display", this.ekMaster ? displayType : "none"); - - // met à jour le menu - if (this.statut === euphorik.Client.statutType.auth_registered) { + + // met à jour le menu + 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);